请告诉我,TPanel是否有可以清除TPanel上所有对象的方法?
例如,如果在TPanel上放置了一些标签(Label.Visible= true),那么在应用该方法之后,它们变得不可见(Label.Visible:= false)。
发布于 2016-04-12 10:55:50
您想销毁TPanel上的所有对象还是只需要隐藏?
如果只需要隐藏面板的所有组件,这些代码可能会帮助您:
面板HideAll组件实例
procedure TForm1.chk_Visible_AllChange(Sender: TObject);
var
n: Integer;
cmp : TComponent;
begin
for n:= 0 to ComponentCount-1 do
begin
cmp := Components[n];
if cmp.GetParentComponent=Panel1 then
begin
if cmp is TLabel then
TLabel(cmp).Visible:= chk_Visible_All.Checked;
if cmp is TButton then
TButton(cmp).Visible:= chk_Visible_All.Checked;
if cmp is TMemo then
TMemo(cmp).Visible:= chk_Visible_All.Checked;
if cmp is TGroupBox then
TGroupBox(cmp).Visible:= chk_Visible_All.Checked;
end;
end;
end; 发布于 2016-04-11 10:20:51
你当然可以用
Panel.Visible = false;以您的面板为父版的所有元素都会更改可见性。
如果在运行时创建控件,则应该为它们分配正确的父级
myLabel.Parent = Panel;https://stackoverflow.com/questions/36541244
复制相似问题