Tester101
Tester101

Reputation: 8172

SplitContainer that only resizes panel1

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?

Upvotes: 2

Views: 13247

Answers (3)

Biniam Eyakem
Biniam Eyakem

Reputation: 554

You can't set the height property of a panel in SplitContainer; but you can capture the Resize event on the form and set the splitterDistance. The SplitContainer will adjust the other panel for you. This is piece of code from my work below and it successfully forced Panel1 to stay the same size when the form resize. Hope this helps

Private Sub frmApp_Resize(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Resize Me.SplitContainer1.SplitterDistance = 140 End Sub

Upvotes: 0

Chris Pfohl
Chris Pfohl

Reputation: 19064

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

Upvotes: 6

Tester101
Tester101

Reputation: 8172

I ended up creating my own control.

Upvotes: -1

Related Questions