Search code examples
delphidelphi-7

TForm issue with scrollbars


I have created a Delphi 7 application. The main form is a TForm object with the below properties:

BorderIcons:
- biSystemMenu = True
- biMinimize = True
- biMaximize = False
- biHelp = False

BorderStyle = bsSizeable

Position = poScreenCenter

Event OnCanResize: Resize := FALSE;

The idea is the form cannot be maximized and cannot be resized, that's all. It works fine, but when I run on certain systems (Windows 7 and Windows XP), there are scrollbars shown. Again, only in certain systems.

I thought this is because the screen resolution of the display is too small, so the app window got clipped. But, it is not. The application was displayed perfectly in the center.

So far, I tried to apply many tricks and tips from the internet:

OnFormShow:

 if VertScrollBarVisible(MainForm.Handle) then
  begin
    MainForm.Constraints.MaxHeight := MainForm.Constraints.MaxHeight + 10;
    MainForm.Constraints.MinHeight := MainForm.Constraints.MinHeight + 10;
    MainForm.Height := MainForm.Height + 10;
  end;

  if HorzScrollBarVisible(MainForm.Handle) then
  begin
    MainForm.Constraints.MaxWidth := MainForm.Constraints.MaxWidth + 10;
    MainForm.Constraints.MinWidth := MainForm.Constraints.MinWidth + 10;
    MainForm.Width := MainForm.Width + 10;
  end;

And it fixed on some systems ... but not all.

This puzzles me.

I got another tips, to set the TForm.Scaled := FALSE, and TForm.AutoScroll := FALSE. That fixed those systems, BUT the bottom of the form was cut off! ... a little bit.

So, now I am asking ...

Are these TForm parameters, like WIDTH, HEIGHT, are saved and stored somewhere in the system??? And the Windows OS forces the app to take that value?

Because, in the past, my app did not have this issue at all. But then, I changed the form size, add some more gui, and then the issue came. Now, I am thinking, the original TForm properties are stored somewhere.


Solution

  • Borders in Windows > XP are bigger. I'm not sure what the Constraints do, cause I haven't used them. Have you tested to use a bigger distance between your components and the right/bottom end of the form?

    EDIT: Some components have different default-sizes on different OS.

    EDIT 2: Your form should not be resizable, so you can turn off the sizing with BorderStyle := bsSingle.