Collapsing and Expanding SplitContainer panels

Saeid Yazdani picture Saeid Yazdani · Dec 8, 2011 · Viewed 17.7k times · Source

I have 3 split containers in my winform application. splitContainer1, splitContainer2, splitContainer3

splitContainer1 is the main split container. in it's panel1 I put splitContainer2 and in its panel2 I have splitContainer3

I then added two buttons to collapse/hide splitContainer3 panels: whenever I click on a button, it gets collapsed, but when I want 2 panels be collapsed, one of them automatically gets expanded again What can be the problem?

private void btToggleCI_Click(object sender, EventArgs e)
{
    switch (splitContainer3.Panel1Collapsed)
    {
        case false:

            splitContainer3.Panel1Collapsed = true;
            btToggleCI.ForeColor = Color.Gray;

            break;

        case true:

            splitContainer3.Panel1Collapsed = false;
            btToggleCI.ForeColor = Color.Black;

            break;
    }
}

private void btToggleTestPlan_Click(object sender, EventArgs e)
{
    switch (splitContainer3.Panel2Collapsed)
    {
        case false:

            splitContainer3.Panel2Collapsed = true;
            btToggleTestPlan.ForeColor = Color.Gray;

            break;

        case true:

            splitContainer3.Panel2Collapsed = false;
            btToggleTestPlan.ForeColor = Color.Black;

            break;
    }
}

Answer

SLaks picture SLaks · Dec 8, 2011

A SplitContainerControl can have up to one panel collapsed.

You can't collapse both panels simultaneously (what would that look like?).