BCB6.0 clears all controls on the TPanel panel

method one:

  The panel->ComponentCount property gets the number of controls owned by the panel

  The panel->Components[i] property gets a control

  delete panel->Components[i]; delete this control

Description, method 1 is suitable for controls that can be edited in an editable interface

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

 

 

Method Two:

      First save the Top, Left, Width, Height and other properties of the panel component

  Then, delete panle;

  Now, generate a new panel, new TPanel;

  Finally, assign the saved panel property to the new panel

        Specify the parent component of the panel panel->parent=?;

Note, Method 2 is applicable to the situation where the program code dynamically creates multiple panel sub-controls as needed, and then needs to be deleted.

   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;

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325232615&siteId=291194637