控件自适应窗体大小(100分)

  • 主题发起人 19721010
  • 开始时间
1

19721010

Unregistered / Unconfirmed
GUEST, unregistred user!
希望窗体中的控件能随窗体大小变化而变化,该如何实现?
 
看看控件的align属性,另外可以在form.resize里改变控件的大小
 
把该控件的align属性 上,下,左, 右全都设为true
 
直接用Align属性
要不就得在Form.OnResize的事件中加代码
可能先算出比例,手工的能过比例改变大小
 
楼上各位:
如果控件没有Alignment属性,又该如何?
我给诸位一个函数供参考。
//Form_width,Form_Height为Form变化前的宽度和高度。
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-1do
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:zhanggm
Form_width,Form_Height变量如何用?
 
在Form中申明为全局变量,在Create时初始化。
 
可以实现了,只是该过程好像不能放在OnSize事件中?
 
我也碰到这样的问题,上位的大侠,你写的函数我怎么测试不成。
 
顶部