BCB6.0 清除TPanel面板上的所有控件

方法一:

  panel->ComponentCount属性获得panel所拥有的控件个数

  panel->Components[i]属性获得某一个控件

  delete panel->Components[i]; 删除此控件

说明,方法一适用于可编辑界面编辑的控件

        for(i=pnl_disPlayPanel->ComponentCount-1;i>=0;i--);
         {
              delete pnl_disPlayPanel->Components[i];
         }

方法二:

      先保存panel组件的Top 、Left、Width、Height 等属性

  然后,delete panle;

  现在,从新生成一个panel ,new TPanel;

  最后,将已保存的panel属性赋值给新的panel

        指定panel的父组件 panel->parent=?;

说明,方法二适用于,程序代码根据需要动态创建多个panel子控件,然后需要删除的情况。

   double pnlTop=0,pnlLeft=0,pnlWidth=0,pnlHeight=0;
   pnlTop=pnl_disPlayPanel->Top;
   pnlLeft=pnl_disPlayPanel->Left;
   pnlWidth=pnl_disPlayPanel->Width;
   pnlHeight=pnl_disPlayPanel->Height;

   delete pnl_disPlayPanel;

   pnl_disPlayPanel = new TPanel(this);
   pnl_disPlayPanel->Top=pnlTop;
   pnl_disPlayPanel->Left=pnlLeft;
   pnl_disPlayPanel->Width=pnlWidth;
   pnl_disPlayPanel->Height=pnlHeight;
   pnl_disPlayPanel->Parent=ts_typeSetPage;

猜你喜欢

转载自www.cnblogs.com/azbane/p/8984011.html