看看这个代码能不能找到: procedure doSplitter(sp:TSplitter); var i:Integer; p:TControl; begin for i:=0 to sp.Owner.ComponentCount-1 do if (sp.Owner.Components[i] is TControl) then Begin p:=sp.Owner.Components[i] as TControl; if p is TSplitter then Continue; if not (sp.Parent=p.parent) then Continue; if not sp.Visible then Continue; if (sp.Align=alleft) and (p.Align=alleft) and (p.Left<=sp.Left) or (sp.Align=alright) and (p.Align=alright) and (p.Left>=sp.Left) then Begin self.rwWidth(p) Continue; End; if (sp.Align=altop) and (p.Align=altop) and (p.Top<=sp.Top) or (sp.Align=albottom) and (p.Align=albottom) and (p.Top>=sp.Top) then begin self.rwHeight(p) Continue; End; End; end;
同一个parent 而且 left小于spliter.left的 控件
能否不用tag,都写成一个通用的方法了要是还要设置这个就没什么用了,那就和直接改变他停靠的位置的控件的大小一个意思了
procedure doSplitter(sp:TSplitter);
var
i:Integer;
p:TControl;
begin
for i:=0 to sp.Owner.ComponentCount-1 do
if (sp.Owner.Components[i] is TControl) then
Begin
p:=sp.Owner.Components[i] as TControl;
if p is TSplitter then
Continue;
if not (sp.Parent=p.parent) then
Continue;
if not sp.Visible then
Continue;
if (sp.Align=alleft) and (p.Align=alleft) and (p.Left<=sp.Left)
or (sp.Align=alright) and (p.Align=alright) and (p.Left>=sp.Left) then
Begin
self.rwWidth(p)
Continue;
End;
if (sp.Align=altop) and (p.Align=altop) and (p.Top<=sp.Top)
or (sp.Align=albottom) and (p.Align=albottom) and (p.Top>=sp.Top) then
begin
self.rwHeight(p)
Continue;
End;
End;
end;
用控件遍历的办法确实是一个办法 可是总有很多未知的问题
比如说你的TSplitter位置你怎么知道是横的还是竖的
而且代码量实在有点不适合
关键是要找它的最近的一个控件我上面的代码只是找到一个就算了
2、在TPanel上放置其它控件