简体   繁体   中英

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.

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

Related to my previous comment on your entire posting. this is a small solution with a ToolBarButton . It will only be enabled if the SplitContainer.Panel1 is collapsed.

Code:

    private void Form1_Load(object sender, EventArgs e)
    {
        splitContainer1.Panel1Collapsed = true;
        toolStripButton1.Enabled = true;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        splitContainer1.Panel1.Hide();
        toolStripButton1.Enabled = true;
    }

    private void toolStripButton1_Click(object sender, EventArgs e)
    {
        if (splitContainer1.Panel1Collapsed)
        {
            toolStripButton1.Enabled = false;
            splitContainer1.Panel1.Show();
        }
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM