c# - Remove other panels on the same form -


i have form (c#) , several panels on it. on 1 panel, put button remove panels on form once clicked. here code:

        mainform = (mainform)this.findform();         foreach (control c in mainform.controls)         {             if (c panel)             {                 mainform.controls.remove(c);                 this.refresh();             }         } 

the problems is: can't find panel on mainform.controls how can solve it? thank you.

at least 1 problem code aren't allowed update list while you're in foreach loop. you're modifying mainform.controls @ same loop you're iterating through it. winforms silently swallows these exceptions , don't realize occurred.

so try creating list of panels front, , see if works. (make sure you've got using system.linq; @ top).

    var panels = mainform.controls.oftype<panel>().toarray();     foreach (var panel in panels)     {         mainform.controls.remove(panel);     } 

Comments

Popular posts from this blog

javascript - DIV "hiding" when changing dropdown value -

Does Firefox offer AppleScript support to get URL of windows? -

android - How to install packaged app on Firefox for mobile? -