开发者

How to deal with form size issues from Delphi 6 and WinXP to Delphi 2007 and Vista/Win7

I have an application written in Delphi 6 and compiled on Windows XP. Usually I leave 8px free between controls and the edges of forms.

When this app runs on Vista or Win 7 this gap is smaller or not present at all. I think this might be because these versions of Windows have thicker form borders.

Now I am moving the app to Delphi 2007. In the form designer the forms have lost the bottom and right gaps.

How should I deal with this? I have hundreds of forms and don't want to go changing them all. Also, most of our users run the app on Win XP so I don't want to make it look bad开发者_如何学JAVA in XP.


Short version: change all form's to AutoScroll = False


The problem is the form's AutoScroll property, and how it affects which form size is stored in the DFM.

If AutoScroll is true (the default) the DFM will store Width and Height:

object Form1: TForm1
  Left = 192
  Top = 114
  Width = 544
  Height = 375
  Caption = 'Form1'
  ...

If AutoScroll is false (the preferred setting) the DFM will store ClientWidth and ClientHeight:

object frmSplash: TfrmSplash
  Left = 192
  Top = 114
  ClientWidth = 536
  ClientHeight = 348
  Caption = 'Form1'

The problem with storing Height is what happens when the user's caption bar is a different size than your development machine, e.g.

  • you develop on Windows 2000, program runs on Windows XP
  • you develop on Windows XP, program runs on Windows Vista
  • you develop with small fonts, program runs with large fonts

Windows 2000 had a 4 pixel border, with a 23 pixel caption bar. With the DFM storing a Height of 375, this leaves 348px for form client area.

Run the same program on Windows XP, which has a taller (28 pixel) caption bar. With the DFM storing a Height of 375 pixels, this leaves 343px for client area.

Your form "got 5 pixels shorter".

You need to force Delphi to store the ClientWidth and ClientHeight in the DFM by turning AutoScroll off.

Now when you create your 348px tall form on Windows XP, it will continue to have 348 pixels in the client area - and be however extra tall is required to have a caption bar.

i go so far as to have an OutputDebugString and a breakpoint trigger if my helper library code finds any form that mistakenly has AutoScroll set to true.


Edit: Since i try to be a good developer, i make my form's respect the user's font preference. During the OnCreate of all my forms i call a StandardizeForm(Self) function that:

  • scales the form to match the user's default font size
  • changes the font on all controls on the form to the user's preference
  • issues an ODS if the form is set mistakenly set to Scaled
  • issues an ODS and breakpoint if AutoScroll true (and sets it to false)
  • issues an ODS and breakpoint if ShowHint is false (and turns it on)
  • etc

You can do something similar. Yes you'd have to add:

procedure TCustomerEditForm.FormCreat(Sender: TObject);
begin
   StandardizeForm(Self); //Pay your taxes!
   ...
end;

But it's worth it for me.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜