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

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
 
M

Morten Wennevik

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top