Search code examples
c#winformssplitcontainer

Expand collpase splitcontainer in win form c#


i am working with split container. my split container has two panel and horizontal orientation. in first panel there are some textboxes and one button. when i click on button then a code run to collapse Panel1 of split container. code is like

 private void button1_Click(object sender, EventArgs e)
 {
        splitContainer1.Panel1Collapsed = !splitContainer1.Panel1Collapsed; 
 }

my problem is when collapse occur then my button and all the textboxes getting invisible. so i next time not being able to make those control visible. so i want trick like button will not be invisible as a result i can click on that button again to make panel1 visible. if possible guide me how to fix or place my button on splitter rather on panel. so guide me how can i do it.


Solution

  • private void button1_Click(object sender, EventArgs e)
    {
        splitContainer1.Panel1Collapsed = !splitContainer1.Panel1Collapsed;
        button1.Parent = splitContainer1.Panel1Collapsed ? splitContainer1.Panel2 : splitContainer1.Panel1;
    }