以前采用如下方法适应800*600与1024*768的分辨率:
inherited;
Font.Name := '宋体';
Font.Size := 9;
//分辨率问题
if(Screen.width <> Orignwidth)then
begin
FWidth:=Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
ScaleBy(Screen.Width,Orignwidth); //控件大小调整
Height:=longint(Height)*longint(Screen.Height) DIV Orignheight;
Width:=longint(Width)*longint(Screen.Width) DIV Orignwidth;//窗口大小调整
end;
但现在大多宽屏显示器,如笔记本是1280*800,或19寸宽屏1440*900,以上这个方法就不适用了,请问大家有什么样的方法可以做到,在1024*768下开发的form能自适应1280*800,或1440*900的宽屏显示器呢?
inherited;
Font.Name := '宋体';
Font.Size := 9;
//分辨率问题
if(Screen.width <> Orignwidth)then
begin
FWidth:=Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
ScaleBy(Screen.Width,Orignwidth); //控件大小调整
Height:=longint(Height)*longint(Screen.Height) DIV Orignheight;
Width:=longint(Width)*longint(Screen.Width) DIV Orignwidth;//窗口大小调整
end;
但现在大多宽屏显示器,如笔记本是1280*800,或19寸宽屏1440*900,以上这个方法就不适用了,请问大家有什么样的方法可以做到,在1024*768下开发的form能自适应1280*800,或1440*900的宽屏显示器呢?
if ((Components[i] is TImage)
or (Components[i] is TDataSource)
or (Components[i] is TClientDataSet))
then exit这种方法,但我想不是所有的控制都转换了,应该怎么办呢?
unit untFixForm;interfaceuses
Classes, SysUtils, Controls, Forms,
ExtCtrls, DBClient, DB;type
TFontedControl = class(TControl) public
property Font;
end; TFontMapping = record
SWidth : Integer;
SHeight: Integer;
FName: string;
FSize: Integer;
end;procedure FixForm(AForm: TForm);
procedure SetFontMapping;var
FontMapping : array of TFontMapping;implementationprocedure SetFontMapping;
begin
SetLength(FontMapping, 5);// 800 x 600
FontMapping[0].SWidth := 800;
FontMapping[0].SHeight := 600;
FontMapping[0].FName := '宋体';
FontMapping[0].FSize := 7;// 1024 x 768
FontMapping[1].SWidth := 1024;
FontMapping[1].SHeight := 768;
FontMapping[1].FName := '宋体';
FontMapping[1].FSize := 9;// 1280 x 1024
FontMapping[2].SWidth := 1280;
FontMapping[2].SHeight := 1024;
FontMapping[2].FName := '宋体';
FontMapping[2].FSize := 11;// 1280 x 800
FontMapping[3].SWidth := 1280;
FontMapping[3].SHeight := 800;
FontMapping[3].FName := '宋体';
FontMapping[3].FSize := 11;// 1280 x 800
FontMapping[4].SWidth := 1440;
FontMapping[4].SHeight := 900;
FontMapping[4].FName := '宋体';
FontMapping[4].FSize := 12;
end;procedure FixForm(AForm: TForm);
var
i, j,x: integer;
t: TControl;
begin
with AForm do
begin
i:=0;
while i<= ComponentCount - 1 do
// for i:=0 to ComponentCount - 1 do
begin
if ((Components[i] is TImage)
or (Components[i] is TDataSource)
or (Components[i] is TClientDataSet))
then exit
else
try
t := TControl(Components[i]);
t.left := Trunc(t.left * (Screen.width / 1024));
t.top := Trunc(t.Top * (Screen.Height / 768));
t.Width := Trunc(t.Width * (Screen.Width / 1024));
t.Height := Trunc(t.Height * (Screen.Height / 768));
except
end; { try } i:=i+1;
end; { for i } for i:= 0 to Length(FontMapping) - 1 do
begin
if (Screen.Width = FontMapping[i].SWidth) and (Screen.Height = FontMapping[i].SHeight) then
begin
for j := 0 to ComponentCount - 1 do
begin
try
TFontedControl(Components[j]).Font.Name := FontMapping[i].FName;
TFontedControl(Components[j]).FONT.Size := FontMapping[i].FSize;
except
end; { try }
end; { for j }
end; { if }
end; { for i }
end; { with }
end;initialization SetFontMapping;end.调用时:
procedure TFrm_Login.FormShow(Sender: TObject);
begin
untFixForm.FixForm(Self);
end;
当然也可以只生成默认的 1024*768Size文件,当分辨率不是默认的1024*768时,根据默认的1024*768的size按比例生成其他分辨率的size。
procedure TForm1.FormCreate(Sender: TObject);
begin
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;
1、FormCreate事件中:
FormResizer1.InitializeForm;
2、FormResize事件中:
FormResizer1.ResizeAll;