The Why and How of the SplitContainer Control - Hide and reveal panels with nested SplitContainers
(Page 5 of 6 )
Just as you can embed a frameset within a frameset in HTML, so you can nest SplitContainer like matryoshka dolls, one inside the other, at the cost of real estate for each getting smaller and smaller. Add a SplitContainer to a form as shown. The default dock property is "fill," that is, the SplitContainer is attached to the four sides of the form. If you change this property to "none" you can make it smaller as shown in the picture.

Click on Panel2 and double click the SplitContainer control in the tool box. This adds another vertical (default orientation) SplitContainer. Right click on Panel2 and choose to look at the properties of SplitContainer2 as shown.

For SplitContainer2 change the orientation from vertical to horizontal. Add four buttons as marked. For the Form load event as well as the click event of the buttons, insert code as shown in the listing. Buttons are marked Button1 to Button 4 from top to bottom.

Public Class nested
Private Sub nested_Load(ByVal sender As Object, _
ByVal e As System.EventArgs) Handles Me.Load
SplitContainer2.IsSplitterFixed = True
SplitContainer1.Panel1.BackColor = Color.GhostWhite
SplitContainer2.Panel1.BackColor = Color.BlanchedAlmond
SplitContainer2.Panel2.BackColor = Color.Ivory
End Sub
Private Sub Button1_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button1.Click 'Hide a panel
SplitContainer1.Panel1.Hide()
End Sub
Private Sub Button2_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button2.Click 'show a panel
SplitContainer1.Panel1.Show()
End Sub
Private Sub Button3_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button3.Click
'collapse a panel SplitContainer1.Panel1Collapsed = True
End Sub
Private Sub Button4_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) Handles Button4.Click
'do not collapse a panel, expand it SplitContainer1.Panel1Collapsed =
False
End Sub
End Class
The default panel color as well as the splitter is hard to see and sometimes disappears; hence "backcolor" was added to the panels to distinguish them from one another and to locate the splitters. While "Hide" and "Show" hide and show the panels, the Boolean values for the Panel collapsed property collapse and expand the panels as shown in the next picture when the Collapse Panel1 button is clicked.

Next: Events related to the SplitContainer Control >>
More .NET Articles
More By Jayaram Krishnaswamy