分辨率的改變 系統字體的變化都有可能引起//Form's Create(Form適應其它分辨率) procedure SetFormCreate(Sender: TForm); begin with Sender do begin Width := FrmMain.myClientWidth; Height := FrmMain.myClientHeight; Top := (FrmMain.myClientHeight - Height) div 2; Left := (FrmMain.myClientWidth - Width) div 2; Scaled := True; if (Screen.Width <> OrignWidth) then begin Height := LongInt(Height) * LongInt(Screen.Height) div OrignHeight; Width := LongInt(Width) * LongInt(Screen.Width) div OrignWidth; ScaleBy(Screen.Width, OrignWidth); end; end; end;
在做程序时,一定要先修改 Form 啦什么的控件的字体修改成 宋体 GB2312字符集 9号或10号字就OK了
系統字體的變化都有可能引起//Form's Create(Form適應其它分辨率)
procedure SetFormCreate(Sender: TForm);
begin
with Sender do
begin
Width := FrmMain.myClientWidth;
Height := FrmMain.myClientHeight;
Top := (FrmMain.myClientHeight - Height) div 2;
Left := (FrmMain.myClientWidth - Width) div 2; Scaled := True;
if (Screen.Width <> OrignWidth) then
begin
Height := LongInt(Height) * LongInt(Screen.Height) div OrignHeight;
Width := LongInt(Width) * LongInt(Screen.Width) div OrignWidth;
ScaleBy(Screen.Width, OrignWidth);
end;
end;
end;
其它控件的ParentFont属性默认值为:true
不要用delphi的默认设置。
implementationconstScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}ScreenHeight: LongInt = 600;{$R *.DFM}procedure TForm1.FormCreate(Sender: TObject);beginscaled := true;if (screen.width <> ScreenWidth) thenbeginheight := longint(height) * longint(screen.height) DIV ScreenHeight;width := longint(width) * longint(screen.width) DIV ScreenWidth;scaleBy(screen.width, ScreenWidth);end;end;下面是解决字体大小的代码:USES typinfo; {Add this to your USES statement.}vari: integer;beginfor i := componentCount - 1 downto 0 dowith components[i] dobeginif GetPropInfo(ClassInfo, 'font') <> nil thenfont.size := (NewFormWidth DIV OldFormWidth) * font.size;end;end;下面的函数可以解决问题:Form:需要调整的Form,OrgWidth:开发时屏幕的宽度,OrgHeight:开发时屏幕的高度。注意:需要把Form的Scaled设置为True。procedure AdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer);beginwith Form dobeginWidth := Width * Screen.Width div OrgWidth;Height := Height * Screen.Height div OrgHeight;ScaleBy(Screen.Width, OrgWidth);end;end; procedure TForm1.Button1Click(Sender: TObject);beginAdjustForm(Self,1280,1024);end;