窗口界面(50分)

C

coldew

Unregistered / Unconfirmed
GUEST, unregistred user!
想问一下大家,就是要写一个自适应窗体的程序(不要叫我搜索一下以前的
贴子)。要求:
1.适应于Win95,Win98,Win200等等各Windows平台。
2.适应于各种字体这就是上面有人提到的。因为繁简体的字体不同,会出现位置的偏差。
3.适应于大小字体,因为我有一个程序(一般都是用小字体写的吧)但结果客户那里以
前有一个程序却是用大字体写的。当然这个界面又是乱七八糟。
4.适应于各种分辨率。因为现在写程序的电脑越来越大了,分辨率也越来越高。但是在
客户那里一般都是上800*600 ,总不能要我们把分辨率调低来做。这样多麻烦。
我想真正的汇总一下这个问题。我知道论坛里有好多这方面的贴子。
分不够我可以另外开贴。
 
Procedure CompentAutoSize(FormeSize:TForm;var Form_width,Form_Height:integer);
var i:integer;
f_Width,f_Height:double;
comtemp:TComponent;
begin
f_Width:=FormeSize.Width/Form_Width;
f_Height:=FormeSize.Height/Form_Height;
// FormeSize.Font.Size:=Trunc(FormeSize.Font.Size*f_Font);
for i:=0 to FormeSize.ComponentCount-1 do
begin
comtemp:=FormeSize.Components;
if comtemp is TGraphicControl then
begin
TGraphicControl(comtemp).Left:=Trunc(TGraphicControl(comtemp).Left*f_Width);
TGraphicControl(comtemp).Width:=Trunc(TGraphicControl(comtemp).Width*f_Width);
TGraphicControl(comtemp).Top:=Trunc(TGraphicControl(comtemp).Top*f_Height);
TGraphicControl(comtemp).Height:=Trunc(TGraphicControl(comtemp).Height*f_Height);
end
else if comtemp is TWinControl then
begin
TWinControl(comtemp).Left:=Trunc(TWinControl(comtemp).Left*f_Width);
TWinControl(comtemp).Width:=Trunc(TWinControl(comtemp).Width*f_Width);
TWinControl(comtemp).Top:=Trunc(TWinControl(comtemp).Top*f_Height);
TWinControl(comtemp).Height:=Trunc(TWinControl(comtemp).Height*f_Height);
end
else if comtemp is TControl then
begin
TControl(comtemp).Left:=Trunc(TControl(comtemp).Left*f_Width);
TControl(comtemp).Width:=Trunc(TControl(comtemp).Width*f_Width);
TControl(comtemp).Top:=Trunc(TControl(comtemp).Top*f_Height);
TControl(comtemp).Height:=Trunc(TControl(comtemp).Height*f_Height);
end;
end;
Form_Width:=FormeSize.Width;
Form_Height:=FormeSize.Height;
end;
 
to yaya8163:
针对你的答案我认为不是我的想法。
1.字体没有变化,所以当你改变控件的高度时是不是出现字符出现在控件位置不好。
或高或低。是不是?
2.如果你想设字体变化,那么你编程时假如在1024*867下设为9号字。在800*600下
字体不就太小了吗?
另外你上现的代码是不是太冗余了,你能不能说明一下为什么,你直接把每一个部件
看成是TControl不行吗。我没有试。你分的三个都是他的子类啦。
综上两条,我认为一个控件的高度不要改变。要改变就最好改变一下多行文本控件。
这样就是不容易出现这一点。
但是其他的一点也没有要求还是没有。但还是谢谢你的参与。
Coldew
2002-12-8
 
我也想知道。
我注视这么久都没人答,是太容易了不屑一答呢。
 
的确不难, 但比较烦。
 
to Another_eYes:
能不能讲一讲。我真的好想知道。我经常遇到这个问题。谢谢你了。
 
to coldew
你好啊!
 
踢一腳……
 
to nibul:
能不能帮我看看这个问题。
 
我认为基本上不可能,但就字体自适应一项就晕!
 
delphi中有一个容器,你可以试试,控件应该就可以自适应了
 
to coldew:
不知道你设计时的操作系统是什么,如果你用的是win2000/xp而客户是98那么,你的程序即使在相同分辨率下控件位置及属性依然会失真,建议您先将yaya8163的方法先调整分辨率,然后在用TRegistry 方法从注册表中判下客户的操作系统是不是98,如果不是就不用再转换,是98的话,那么
你用上述yaya1863的方法将各属性包括 font大小都 *100/125。当然了如果你的程序是98下设计编译就不用此步骤了。这种方法至少在我的程序上是这样写的。
 
为什么这个问题就没有人回答呢?
纳闷!
to emyjob:
为什么好多程序都可以做到DELPHI却不能呢?
 
怎么这个问题摆了这么久都没有答案了吗?
 
我知道如何使窗体大小不依赖于屏幕分辨率。需要为窗体添加OnCreate事件处理过程
const
//定义两个全局变量,用于保存设计窗体时的屏幕分辨率
ScreenHeight:integer=800;
ScreenWidth:integer=600;
FormCreate事件:
var x,y:longint;
begin
Form1.Sacled:=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;
 
要判断是那个版本的windows用GetSystemDefaultLangID

下面是一段例子:

LangID:integer;

Langid:=GetSystemDefaultLangID;

if LangID= ((SUBLANG_CHINESE_SIMPLIFIED shl 10) or LANG_CHINESE) then
//简体中文

各种常数都可以到Win32 API help中去查.
const
ScreenWidth: Integer =800;
ScreenHeight: Integer =600;

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;
我给你查的以前的贴字可以完成你的1,跟4,
 
这个问题也没有什么结果算了。散分吧。不甘心。
 
顶部