C# Windows Form - Panel populated dynamically with button controls, Windows.Closing() becomes disabl

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

The form has a panel that is populated in c# code. Panels containing button controls and label controls are added to the main panel. The first time the form is displayed it works fine. When the user initiates an activity, I execute code as follows
pnlPlots.Controls.Clear()
Then pnlPlots is populated again. The form continues to work, but it cannot be closed with Windows.Closing() or a menu item with this.Close();

If the panel is populated with label controls only (no button controls), this problem does not occur

Thank you
Bruc
 
Hi Bruce,

What happens if you instead of pnlPlots.Controls.Clear() do

foreach(Control c in pnlPlots)
{
if((c is Label) || (c is Button))
{
pnlPlots.Remove(c);
c.Dispose();
}

}

Happy coding!
Morten
 
Back
Top