Reputation: 6451
I have groupbox I want to clear all the control in it , I try
public void ClearPanels(GroupBox control)
{
foreach (Control p in control.Controls)
{
control.Controls.Remove(p);
}
}
but a panel remain it , the problem I create the controls in runtime , and want to remove it in runtime
Upvotes: 1
Views: 1117
Reputation: 31250
Use RemoteAt
while (control.Controls.Count > 0)
{
control.Controls.RemoveAt(0);
}
or Clear
control.Controls.Clear();
Upvotes: 2
Reputation: 25732
Better use this which clears all the controls at once without using a loop:
public void ClearPanels(GroupBox control)
{
control.Controls.Clear();
}
Upvotes: 3