SplitContainer that only resizes panel1

Tester101 picture Tester101 · Aug 13, 2010 · Viewed 12.5k times · Source

Is there a way to make the SplitContainer only adjust the size of panel1? I have a Vertical SplitContainer and when I move the splitter I would like the size of the first panel to increase/decrease, but rather than change the size of the second panel I want the form to increase and decrease in size.

I created some code to increase/decrease the size of the form, but Panel2 is also changing size so the entire panel is not always visible.

Am I going to have to make my own container, or is this possible with the SplitContainer?

I have a form "MainWin" that contains a Panel "MainPanel" MainPanel contains the SplitContainer "MainSplitContainer". Panel1 contains a TreeView, and Panel2 contains 3 Panels that are made visible based on which item is selected in the TreeView. I want these 3 Panels to always be completely visible (I'm planning to limit the expansion of the splitter so the form cannot expand beyond the screen), is this possible or should I just create my own control and adjust the size of things using the MouseDown, MouseUp, and MouseMove events?

Answer

Chris Pfohl picture Chris Pfohl · Oct 5, 2010

There's no need to create your own form: SplitContainer has a property: "FixedPanel" Select the SplitContainer and in the Layout section look at "FixedPanel" Set it to the panel you want to stay constant in width or height (depending on the panel layout).

Programatically:

sc.FixedPanel = FixedPanel.Panel1; //Or Panel2

See:

Splitcontainer, Make a fixed panel

Fixed Panel Height in a SplitContainer