如何处理从Delphi 6和WinXP到Delphi 2007和Vista / Win7的表单大小问题 [英] How to deal with form size issues from Delphi 6 and WinXP to Delphi 2007 and Vista/Win7

查看:152
本文介绍了如何处理从Delphi 6和WinXP到Delphi 2007和Vista / Win7的表单大小问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个用Delphi 6编写的应用程序,并在Windows XP上编译。通常我在控件和窗体边缘之间留下8px的空格。



当这个应用程序在Vista或Win 7上运行时,这个差距更小或者根本就不存在。我认为这可能是因为这些版本的Windows具有较厚的边框。



现在我将应用程序移动到Delphi 2007.在窗体设计器中,窗体已经丢失了底部和正确的差距。



我该怎么处理?我有数百种形式,不想改变他们。此外,我们的大多数用户在Win XP上运行该应用程序,所以我不想让它在XP中看起来不好。

解决方案

简短版本:将所有表单更改为 AutoScroll = False






问题是表单的 AutoScroll 属性,以及它如何影响DFM中存储的表单大小。



如果 AutoScroll true (默认),DFM将存储宽度高度

 对象Form1:TForm1 
左= 192
顶部= 114
宽度= 544
高度= 375
标题='Form1'
...

如果 AutoScroll false 首选设置)DFM将存储 ClientWidth ClientHeight

 对象frmSplash:TfrmSplash 
左= 192
顶部= 114
ClientWidth = 536
Clie ntHeight = 348
Caption ='Form1'

存储高度是用户的标题栏与开发机器不同的大小,例如




  • 您在Windows 2000上开发,在Windows XP上运行程序

  • 您在Windows XP上开发,在Windows Vista上运行程序

  • 您使用小字体开发,具有大字体的程序运行



Windows 2000具有4像素边框,带有23像素字幕栏。使用DFM存储的高度为375,这为表单客户端区域留下348px。



运行相同的程序Windows XP具有较高的(28像素)标题栏。使用DFM存储375像素的高度,这为客户区域留下343px。



您的表单得到5像素较短



您需要强制Delphi存储 ClientWidth ClientHeight 转动 AutoScroll 关闭。



现在,当您创建348px高的形式在Windows XP上,它将在客户端区域继续拥有348像素,而且需要额外的高度才能使用标题栏。



有一个 OutputDebugString 和一个断点触发器,如果​​我的帮助程序库代码找到任何错误地将 AutoScroll 设置为






编辑由于我尽量成为一名好的开发者,我使我的表单尊重用户的字体偏好。在我所有表单的 OnCreate 中,我调用一个 StandardizeForm(Self)函数:




  • 缩放表单以匹配用户的默认字体大小

  • 将表单上所有控件上的字体更改为用户的首选项

  • 如果表单被设置为错误设置为,则会发出消耗臭氧层物质
  • 问题如果 AutoScroll true(并将其设置为false),则将ODS和断点

  • 发出ODS和断点,如果 ShowHint 是false(并打开它)




你可以做类似的事情。是的,你必须添加:

 过程TCustomerEditForm.FormCreat(发件人:TObject); 
begin
StandardizeForm(Self); //缴纳税款!
...
end;

但这对我来说是值得的。


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 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.

这篇关于如何处理从Delphi 6和WinXP到Delphi 2007和Vista / Win7的表单大小问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆