在一定的分辨率下设计界面,为了适应不同的分辨率,添加一段专门的代码:
const
ScreenWidth: LongInt = 800; {I designed my form in 800x600 mode.}
ScreenHeight: LongInt = 600;
{$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).Font.Size :=
(NewFormWidth div OldFormWidth) *TFooClass(Controls).Font.Size;
end;