Cannot set splitContainer.Panel2 width or height

rfresh

Active member
Joined
Aug 23, 2012
Messages
26
Programming Experience
1-3
I've added a splitContainer to my form but I can't figure out how to set the splitContainer.panel2 width and height? I have two panels: splitContainer.Panel1 and splitContainer.panel2.


I have the splitContainer.Dock set to Left.


When I try to set the splitContainer.panel2 width I get an error saying to set the Distance. The Distance is from the left or top. I have the splitContainer dock set to Left but that's for the main splitContainer.panel1 isn't it?


So how do I set splitContainer.panel2 width and height?


Thank you...
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,138
Location
Sydney, Australia
Programming Experience
10+
You don't set the size of the panels directly. You will have set the Size of the SplitContainer itself and then you set the SplitterDistance. That will inherently set the size of the panels. If your control is 105 pixels wide, the splitter bar is 5 pixels wide and you set the SplitterDistance to 50, the first panel will be 50 pixels wide and so will the second. It's simple maths.
 

rfresh

Active member
Joined
Aug 23, 2012
Messages
26
Programming Experience
1-3
After searching hours and hours for a solution, I finally found it, so I will share it here:

If you want to set splitContainer.Width and/or .Height and/or it's .Top and .Left, the splitContainer.Dock property must be set to .None. That was the key for me.
 

jmcilhinney

C# Forum Moderator
Staff member
Joined
Apr 23, 2011
Messages
3,138
Location
Sydney, Australia
Programming Experience
10+
After searching hours and hours for a solution, I finally found it, so I will share it here:

If you want to set splitContainer.Width and/or .Height and/or it's .Top and .Left, the splitContainer.Dock property must be set to .None. That was the key for me.
That's not true. Obviously, if the Dock property is set to Left then the Top and Left properties will be fixed but you can still set the Width of the SplitContainer. You still can't set the width of the individual panels though. They are a function of the Width, SplitterDistance and SplitterWidth of the SplitContainer, regardless of whether you've docked it or not.
 
Top Bottom