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[i] do
begin
if GetPropInfo(ClassInfo, 'font') <> nil then
font.size := (NewFormWidth DIV OldFormWidth) * font.size;
end;
end;
下面的函数可以解决问题:
Form:需要调整的Form,OrgWidth:开发时屏幕的宽度,OrgHeight:开发时屏幕的高度。
注意:需要把Form的Scaled设置为True。
procedure AdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer);
begin
with Form do
begin
Width := Width * Screen.Width div OrgWidth;
Height := Height * Screen.Height div OrgHeight;
ScaleBy(Screen.Width, OrgWidth);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AdjustForm(Self,1280,1024);
end;
procedure TForm1.FormCreate(Sender: TObject);
var
devmode:tDevicemode;
begin
if screen.width<>orignwidth then
begin
if EnumDisplaySettings(nil,0,devmode) then
begin
devmode.dmfields:=dm_pelswidth OR dm_pelsheight ;
devmode.dmpelswidth:=orignwidth; {宽度}
devmode.dmpelsheight:=orignheight;{高度}
ChangeDisplaySettings(devmode,0); {更改设置}
end;
end;
end;
procedure TMain_f.FormCreate(Sender: TObject);
begin
if GetSystemMetrics(SM_CXSCREEN)>800 then
begin
main_f.WindowState:=wsMaximized;
end
else
begin
main_f.WindowState:=wsNormal;
width:=800;
height:=572;
top:=0;
left:=0;
end;
Another_eYes (1998-11-22 22:39:29)
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[i] do
begin
if GetPropInfo(ClassInfo, 'font') <> nil then
font.size := (NewFormWidth DIV OldFormWidth) * font.size;
end;
end;
下面的函数可以解决问题:
Form:需要调整的Form,OrgWidth:开发时屏幕的宽度,OrgHeight:开发时屏幕的高度。
注意:需要把Form的Scaled设置为True。
procedure AdjustForm(Form: TForm; const OrgWidth, OrgHeight: integer);
begin
with Form do
begin
Width := Width * Screen.Width div OrgWidth;
Height := Height * Screen.Height div OrgHeight;
ScaleBy(Screen.Width, OrgWidth);
end;
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
AdjustForm(Self,1280,1024);
end;