Search code examples
c#winformspanel

Panels behavior : separation


I have 3 panels on top of each others and 3 buttons. What I want to achieve is with every button click its correspondent panel appears, currently I am using panel.Visible = true; and panel.Visible = false; but since every element over a panel in a WFA is considered a child of that panel all I get is either they are all visible or they are all invisible.

Q: How to make each panel behave separately?

This is the visibility control code:

private void btnHome_Click(object sender, EventArgs e)
{
    panelHome.Visible = true;
    panelContact.Visible = false;
    panelOther.Visible = false;
}

private void btnContact_Click(object sender, EventArgs e)
{
    panelHome.Visible = false;
    panelContact.Visible = true;
    panelOther.Visible = false;
}

private void btnOther_Click(object sender, EventArgs e)
{
    panelHome.Visible = false;
    panelContact.Visible = false;
    panelOther.Visible = true;
}

Solution

  • This issue is easly solved using the graphical user interface:

    You just need to carefully place every panel on top of the previous one until the blue guidelines appear.

    PS: You need to check 2 guidelines: one vertical (left or right) and one horizontal (top or bottom)