Change the height of the panel of the split container at runtime

4.8k Views Asked by At

I have a splitcontainer and I would change the height of the panel1 at runtime. I use this code

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click
        SplitContainer1.Panel1.Height = 2
    End Sub

It's possible ? Does anybody have any suggestion?

Thanks a lot in advance.

2

There are 2 best solutions below

0
On BEST ANSWER

I think you're looking for the property SplitContainer.SplitterDistance. From the documentation:

Gets or sets the location of the splitter, in pixels, from the left or top edge of the SplitContainer.

0
On

Per my comment, you should consider just calling

splitContainer1.Panel1Collapsed = true;

since the height of 2 is a very small number. Not much use to the user.

Otherwise, you would have to set the following two properties:

splitContainer1.Panel1MinSize = 2;
splitContainer1.SplitterDistance = 2;