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
Post a Comment