楼上各位:
如果控件没有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;