How can I hide a panel that is on a SplitContainer?

Viewed 39331

I want to hide panel2 on a split container and have panel1 utilize the space. I was hoping setting Panel2Collapsed would do the trick, but no luck. Ideas?

6 Answers

This worked for me on a similar situation:

splitContainer1.Panel2Collapsed = true;
splitContainer1.Panel2.Hide();

I wanted the second panel to not be visible at all in some cases, so I implemented it this way.

Setting Panel2Collapsed property to true in the form designer and programatically both work as you want them to (i.e. Panel1 then occupies all of the space)... so there must be something else going on.

With Visual Studio 2017 it is a little more trick. This is what I got to work for me. MyControl is inside panel1.

'vb.net:

MySplitContainer.Panel2Collapsed = True
MySplitContainer.Panel2.Hide()
MySplitContainer.SplitterDistance = MySplitContainer.Height
MySplitContainer.Panel1.Anchor = AnchorStyles.Bottom
MyControl.Height = MySplitContainer.Height

'for C# just add a semi-colon onto the end of each line and it should work.

Try setting panel2.Visible = false.

Related