0

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.

Thomas
  • 33,544
  • 126
  • 357
  • 626
  • Isn't it quite obvious that you can't click on a `Button` that is part of a collapsed `SplitContainer.Panel1`? You better store your `Button` in a `ToolBar` or as a `MenuItem` that will be enabled/disabled according to the collapse state. – varg Aug 30 '12 at 20:07

2 Answers2

4
private void button1_Click(object sender, EventArgs e)
{
    splitContainer1.Panel1Collapsed = !splitContainer1.Panel1Collapsed;
    button1.Parent = splitContainer1.Panel1Collapsed ? splitContainer1.Panel2 : splitContainer1.Panel1;
}
coolmine
  • 4,427
  • 2
  • 33
  • 45
  • after the second click to do some work and collapsing the panel again, this button vanished and you can't click it again. – varg Aug 30 '12 at 20:59
  • 1
    I can't duplicate what you are saying. In my case the button says on the same position while being visible while the rest of the controls disappear. Maybe it's hiding behind another control ? Add button1.BringToFront(); at the end and verify that. – coolmine Aug 30 '12 at 21:06
  • hiding behind a small unimposing groupbox. damn you, control! :) - nice solution! – varg Aug 30 '12 at 21:16
  • sorry ur tips does not work. this line button1.Parent = splitContainer1.Panel1Collapsed ? splitContainer1.Panel2 : splitContainer1.Panel1; do not work. if possible please instruct me how should i design the form. thanks – Thomas Aug 31 '12 at 07:01
  • Did you read the comment above ? Maybe you are having the same issue varg had ? – coolmine Aug 31 '12 at 08:00
  • can u give a sample code what u have said....because things is not getting clear to me the way u try to solve. thanks – Thomas Sep 01 '12 at 15:07
  • Most likely your button is hiding behind another control when you click the button. button1.BringToFront() will bring it to the front so it will be visible again. So the only thing you have to do is add button1.BringToFront() to the answer above. – coolmine Sep 01 '12 at 15:59
0

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();
        }
    }
varg
  • 3,446
  • 1
  • 15
  • 17