真的要解决是十分困难的,你要与系统打交道,获得系统事件,FORMRESIZE事件,
并在其中改变每一个控件的大小(可以用FOR I:= 0 TO CONPONENTCOUNT DO
CONPONENTS AS ...来实现)
我用的方法最简单:在640*480下写程序,不让程序改变窗口的大小,或者不让程序
超过我指定大大小,在FORM的ONRESIZE事件中解决,大概的代码如下:
IF SELF.HEIGHT = XXX THEN
SELF.HEIGHT := XXX;
IF SELF.WIDTH := XXX THEN
SELF.WIDTH :=XXX;
这样,不管在800*600还是在1024*768都OK
implementation
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;
下面是解决字体大小的代码:
USES typinfo; {Add this to your USES statement.}
var
i: integer;
begin
for i := componentCount - 1 downto 0 do
with components do
begin
if GetPropInfo(ClassInfo, 'font') <> nil then
font.size := (NewFormWidth DIV OldFormWidth) * font.size;
end;
end;