首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > .NET > .NET >

遍历控件.help,该如何处理

2012-02-14 
遍历控件.....helpfunctionAUTOAdapt(Tfm:TWinControl{容器}wint1,hint1:Integer{开发时的分辨率}DeftB:

遍历控件.....help
function   AUTOAdapt(Tfm:TWinControl{容器};wint1,hint1:Integer{开发时的分辨率};DeftB:Boolean=false{容器是否也调整}):Boolean;
var
    i,j:Integer;
    vl_ScreenWidth,vl_ScreenHeight:   LongInt;
    WRadio,HRadio   :     double   ;
    temp:TControl;
begin
try
result:=false;
  vl_ScreenWidth     :=   Screen.Width;
  vl_ScreenHeight   :=   screen.height;
WRadio   :=   vl_ScreenWidth/wint1   ;
HRadio   :=   vl_ScreenHeight/hint1   ;
if   (WRadio=1)   and   (HRadio=1   )   then
begin
    Result:=True;   Exit;
end;    
if   DeftB=true   then
with   Tfm   do
begin
    Width:=Round(width*WRadio);
    Height:=Round(Height*HRadio);
    left:=Round(left*WRadio);
    top:=Round(top*HRadio);
end;

for   i:=0   to   (Tfm.ControlCount)-1     do
begin
temp:=Tfm.Controls[i];
    with   temp   do
    begin
        Width:=Round(width*WRadio);
        Height:=Round(Height*HRadio);
        left:=Round(left*WRadio);
        top:=Round(top*HRadio);
    end;
    try
        if   UpperCase(temp.ClassName)= 'TTOOLBAR '   then
        with   (temp   as   TTOOLBAR)   do
        begin
            buttonWidth:=Round(buttonwidth*WRadio);
            buttonHeight:=Round(buttonHeight*HRadio);
        end
        else
        if   (temp   as   TWinControl).ControlCount> 0   then   //如果是容器就   递归调用
            AUTOAdapt(temp   as   TWinControl,wint1,hint1,false);
    except
        Exit;    
    end;
end;
result:=True;
except
    Result:=False;
end;
end;

此函数有什么   缺陷??
怎么样才能达到目的

[解决办法]
temp:TControl;
如果只是作为容器范围太大
[解决办法]
你可以用ScaleBy

热点排行