views:

59

answers:

2

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?

A: 

I ended up creating my own control.

Tester101
A: 

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:

http://stackoverflow.com/questions/2405143/splitcontainer-make-a-fixed-panel

http://stackoverflow.com/questions/1373596/fixed-panel-height-in-a-splitcontainer

Cpfohl
I think I tried this, but it did not give me the desired results.
Tester101
Oh! I misread the question: Set your FixedPanel to the panel you don't want changing (this fixes the panel while changing the size of the form itself), and set IsSplitterFixed to False (giving you the choice to change the panel widths). Save the width of the fixed panel at construction and then whenever SplitterMoved fires if( <not-fixed-panel>.<Dimension> != <correct-size> ) you can adjust the form size based on the non-permanent panel size and the fixed panel's intended size. Finally move the splitter again, and this time (since you have the if) it won't re-size it again.
Cpfohl
Although a custom container may be just as easy! ;)
Cpfohl