tags:

views:

1390

answers:

3

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?

A: 

Try setting panel2.Visible = false.

Andrew Peters
A: 

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.

Daniel LeCheminant
+8  A: 

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.

Nikos Steiakakis
If you don't set the SplitterDistance and calling Hide(), which part of Panel2 is visible?
Daniel LeCheminant
If I recall correctly, if you didn't set the SplitterDistance, then at the far end of Panel1 the mouse cursor would change, making it evident that there is another panel there.
Nikos Steiakakis
but what happens when the user resizes the form
CrashCodes
@Nikos: Hmm... I can't recreate that :-/ That kind of issue exists with the `Splitter` control, but I thought the whole purpose of the SplitContainer was to do away with those issues...
Daniel LeCheminant
@CrashCodes: If the splitcontainer is docked, or properly anchored it will resize with the form, and Panel1 will stay docked to fill the entire splitcontainer.
Nikos Steiakakis
Okay. Tried it works great. I started removing lines to see which one did the trick; and I'm back down to splitContainer1.Panel2Collapsed = true; Fun stuff.
CrashCodes
@CrashCodes: Meaning that just setting Panel2Collapsed works?
Daniel LeCheminant
@Daniel L: You're right, it doesn't do that! I checked it out and most probably setting the SplitterDistance equal to the total width is most probably just redundant.
Nikos Steiakakis
Yeah. Does now. Hot stuff.
CrashCodes
Thanks guys, at least I know that I'm not crazy! Glad you got it to work :]
Daniel LeCheminant
@Nikos: I think the .Hide() is redundant as well...
Daniel LeCheminant