Winforms panels overlapping listening

Oh wow this annoys me. Using C #, winforms, visual studio 2010 ulti.

Here's my code:

private void CheckBoxBranch_CheckedChanged(object sender, EventArgs e)
{   

    if (CheckBoxBranch.Checked == true)
    {
        panelBranch.Visible = true;
        //panelBranch.Parent = null;
        //PanelBuyer.Parent = null;
        //panelBranch.SendToBack();
        //PanelBuyer.SendToBack();
        PanelBuyer.Visible = false;
        CheckBoxBuyer.Checked = false;
        this.Refresh();
    }
    if (CheckBoxBranch.Checked == false)
    {
        panelBranch.Visible = false;
        this.Refresh();
    }

}

private void CheckBoxBuyer_CheckedChanged(object sender, EventArgs e)
{
    if (CheckBoxBuyer.Checked == true)
    {
        panelBranch.Visible = false;
        PanelBuyer.Visible = true;
        CheckBoxBranch.Checked = false;
        this.Refresh();
    }
    if (CheckBoxBuyer.Checked == false)
    {
        PanelBuyer.Visible = false;
        this.Refresh();
    }
}

      

now this code works fine, no problem if the panels are not on top of each other. When this happens, the Buyer Panel works fine, Panel-Branch is never shown at all.

Now I think it has something to do with the branch bar becoming a child of the buyer bar, so when my logic works for the buyer it also applies to the branch.

I could convert there positions every time, like a rotation, but with a lot of extra code.

Is there a way to solve this headache, a nice short sweet and simple liner? (I wish).

+3


source to share


2 answers


Make sure one panel is not inside another panel.

An easy way to avoid this is by manually setting the location property in the designer. Don't use your mouse to drag the controls into place.



You can also use the window View

- Other Windows

- Document Outline

to make sure the panels are not inside each other.

+9


source


I guess the problem is that one panel sits on top of the other, becoming a child of the other panel, so you cannot set it to true. To check that you can right click on your panel and if you have the option to select a different panel then it is clear that the panel has another panel as parent



0


source







All Articles