foreach (Control c in this.Controls)
{
if (c is Panel) c.Visible = false;
}
And you could even make that recursive, and pass in the ControlCollection
instead of using this.Controls
:
HidePanels(this.Controls);
...
private void HidePanels(ControlCollection controls)
{
foreach (Control c in controls)
{
if (c is Panel)
{
c.Visible = false;
}
// hide any panels this control may have
HidePanels(c.Controls);
}
}