首先,将比例调整为原始比例,然后比例调整为新比例。例如,要在 OnResize 事件中缩放表单:
...
private
FDesignHeight: Integer;
FDesignWidth: Integer;
FPrevWidth: Integer;
end;
...
procedure TForm1.FormShow(Sender: TObject);
begin
FDesignHeight := Height;
FDesignWidth := Width;
FPrevWidth := Width;
Scaled := True;
end;
procedure TForm1.FormResize(Sender: TObject);
begin
if Scaled then
begin
DisableAlign;
ScaleBy(FDesignWidth, FPrevWidth);
ScaleBy(Width, FDesignWidth);
EnableAlign;
end;
FPrevWidth := Width;
end;
procedure TForm1.FormCanResize(Sender: TObject; var NewWidth,
NewHeight: Integer; var Resize: Boolean);
begin
NewHeight := Round(NewWidth * FDesignHeight / FDesignWidth);
end;