您的位置:首页 > 其它

使form适应不同的显示分辨率

2006-03-12 16:24 375 查看

版权声明

请尊重原创作品。转载请保持文章完整性,并以超链接形式注明原始作者“tingsking18”和主站点地址,方便其他朋友提问和指正。

假设你在800*600的分辨率下设计的form,第一步:
inplementation
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;


========================================
使窗体大小不依耐屏幕的分辨率(T)

const
ScreenHeight:INTEger=800;
ScreenWidth:integer=600;

Prodedure Tform1.formcreate(Sender:tobject);
var
x,y:Longint;
begin
form1.scaled:=true;
x:=getsystemmetrics(SM_CXSCREEN);
y:=Getsystemmetrics(SM_CYSCREEN);
IF(X<> SCREENHEIGHT)or (Y<>SCREENWIDTH) then
BEGIN
FORM1.HEIGHT:=FORM1.HEIGHT*X DIV SCREENHEIGHT;
FORM1.WIDTH:=FORM1.WIDTH*Y DIV SCREENWIDTH;
scaleBy(X,SCREENHEIGHT);
END

end;
end;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: