显示问题 ( 积分: 20 )

  • 主题发起人 主题发起人 hhycqrm
  • 开始时间 开始时间
H

hhycqrm

Unregistered / Unconfirmed
GUEST, unregistred user!
怎么让窗口能自动根据显示器的分辨率来显示.
 
怎么让窗口能自动根据显示器的分辨率来显示.
 
api取当前分辨率,然后再做处理.
 
procedure TForm1.FormCreate(Sender: TObject);
var
FWidth:integer;
begin
//自动分辨率
if(Screen.width<> 800)then
begin
FWidth:=Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
ScaleBy(Screen.Width,800);
//控件大小调整
Height:=longint(Height)*longint(Screen.Height)DIV 600;
Width:=longint(Width)*longint(Screen.Width)DIV 800;//窗口大小调整
end;

end;
 
还是不行..我在1024*768的分辨率下做了一个界面.可以800*600的分辨率下面显示还是有滚动条,我现在只用两种分率还没加其它的.
procedure TForm1.FormCreate(Sender: TObject);
var
FWidth:integer;
begin
//自动分辨率
if(Screen.width=800)then
begin
FWidth:=Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
ScaleBy(Screen.Width,800);
//控件大小调整
Height:=longint(Height)*longint(Screen.Height)DIV 600;
Width:=longint(Width)*longint(Screen.Width)DIV 800;//窗口大小调整
end
else
begin
FWidth:=Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;//字体大小调整
ScaleBy(Screen.Width,1024);
//控件大小调整
Height:=longint(Height)*longint(Screen.Height)DIV 768;
Width:=longint(Width)*longint(Screen.Width)DIV 1024;//窗口大小调整
end
end;

好像他的控件没有根据窗口的大小而改变.
 
TO wolf_cyj,hhycqrm:
您們的方法我想應該可行的! 不過可能要作小小調整. 參考您們的做法, 我作了小小調整, 請指教:
unit test;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms, Dialogs;
Const
MySetWidth = 800;
MySetHeight = 600;

type
TForm1 = class(TForm)
procedure FormCreate(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;

var
Form1: TForm1;
implementation
{$R *.dfm}
方法一:
procedure TForm1.FormCreate(Sender: TObject);
begin
Scaled := True;
if (Screen.Width<>MySetWidth) then
begin
Height := longint(Height)*longint(Screen.height) div MySetHeight;
Width := longint(Width) * longint(Screen.Width) div MySetWidth;
ScaleBy(Screen.Width, MySetWidth);
end;
end;

方法二:
procedure TForm1.FormCreate(Sender: TObject);
var
devmode: tDevicemode;
begin
if Screen.Width <> MySetWidth then
begin
if EnumDisplaySettings(nil,0,devmode) then
begin
devmode.dmFields := DM_PELSWIDTH or DM_PELSHEIGHT;
devmode.dmPelsWidth := MySetWidth;
// 寬度
devmode.dmPelsHeight := MySetHeight;
// 高度
ChangeDisplaySettings(devmode,0);
// 更改設置
end;
end;
end;

end.

這兩种方法雖然都可以改變屏幕的在小, 但始終不能解決其刷新率的問題.
 
FWidth:integer;
begin

FWidth:=form1.Width;
Scaled:=TRUE;
Font.Size:=(Width DIV FWidth)*Font.Size;
ScaleBy(Screen.Width,form1.width);
form1.Height:=longint(Height)*longint(Screen.Height)DIV Screen.Height;
form1.Width:=longint(Width)*longint(Screen.Width)DIV Screen.Width;
这样可以自动根据显示分辨率改变了.
前面的都有限制..只能在800*600或是1024*768.
但是在里面的有些倥件就不行了..比如说QQ导航条,,,
 
多人接受答案了。
 
后退
顶部