Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

how to hide all panels in windows form?

In my windows application which uses menu strip and multiple panel containers, a panel is displayed depending on menu option

hiding all panels by manually passing names is very time consuming, is there any way to hide all panels or any way to get names of all panels in a form??

like image 939
Abhinav Garg Avatar asked Jun 06 '13 19:06

Abhinav Garg


People also ask

How do I hide windows form title bar?

if by Blue Border thats on top of the Window Form you mean titlebar, set Forms ControlBox property to false and Text property to empty string ("").

How do I make a Windows Form full screen?

The easiest way to go full screen in an application or a game is to use the Alt + Enter keyboard shortcut. This method works for most games and apps unless they use it to enable other features. The shortcut is also used to switch from full-screen mode to windowed.


1 Answers

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);
    }
}
like image 172
Mike Perrenoud Avatar answered Sep 28 '22 02:09

Mike Perrenoud