inplementation const ScreenWidth: LongInt = 1024; {I designed my form in 1024×768 mode.} ScreenHeight: LongInt = 768;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject); begin scaled := true; if (screen.width <> ScreenWidth) then begin height := longint(height) * longint(screen.height) div ScreenHeight; width := longint(width) * longint(screen.width) div ScreenWidth; scaleBy(screen.width, ScreenWidth); end; end;下一步,要每個子控制的字体改變到合适的大小: type TFooClass = class(TControl); { needed to get at protected } { font property }var i: integer; begin for i := ControlCount - 1 downto 0 do TFooClass(Controls[i]).Font.Size := (NewFormWidth div OldFormWidth) * TFooClass(Controls[i]).Font.Size; end;
inplementation
const
ScreenWidth: LongInt = 1024; {I designed my form in 1024×768 mode.}
ScreenHeight: LongInt = 768;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);
begin
scaled := true;
if (screen.width <> ScreenWidth) then
begin
height := longint(height) * longint(screen.height) div ScreenHeight;
width := longint(width) * longint(screen.width) div ScreenWidth;
scaleBy(screen.width, ScreenWidth);
end;
end;下一步,要每個子控制的字体改變到合适的大小:
type
TFooClass = class(TControl); { needed to get at protected }
{ font property }var
i: integer;
begin
for i := ControlCount - 1 downto 0 do
TFooClass(Controls[i]).Font.Size :=
(NewFormWidth div OldFormWidth) *
TFooClass(Controls[i]).Font.Size;
end;
Form1.ScaleBy(768,1024);
還有調整控件的Align和Anchors屬性可以滿足這方面的需要.
可以在窗体未显示之前通过Screen对象中获取的信息设置窗体大小,但是如果你在1024*768下设计的窗体大于800*600时,想在800*600的分辨率下获得良好的视图,比较麻烦,一般来说,由于800*600的分辨率显示器还很普遍,我们公司的软件界面,限制不能超过780*540,除非确定客户绝对不会在800*600分辨率下使用软件。