Next: Splitter Demo 2
This example demonstrates using a Splitter control to host two forms at a
time. In this example, the user can select which form to display in the
right-hand or bottom pane, by selecting an item from the TreeView in the
left-hand or top pane.
Related Help topics:
ChildForm1 and ChildForm2 Properties
Orientation Property
Open zip file
Navigation between the different pages is accomplished by clicking on a
TreeView which is hosted on the form cfmNavigation. The Load event handler
for cfmNavigation is shown below:
Private Sub Form_Load()
'Initialize the Treeview
TreeView1.Nodes.Add , , "About", "About"
TreeView1.Nodes.Add , , "Page1", "Page1"
TreeView1.Nodes.Add , , "Page2", "Page2"
End Sub |
The NodeClick event for the TreeView is below:
Private Sub
TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
'Set the Active Page based on which node was clicked.
Select Case Node.Key
Case "About"
Set frmMain.ActivePage = cfmAbout
Case "Page1"
Set frmMain.ActivePage = cfmPage1
Case "Page2"
Set frmMain.ActivePage = cfmPage2
End Select
End Sub |
The ActivePage property is implemented in code, in frmMain:
Public Property Set
ActivePage(ByRef frm As Form)
Set Splitter1.ChildForm2 = frm
End Property
Public Property Get ActivePage() As Form
Set ActivePage = Splitter1.ChildForm2
End Property |
An alternative way of implementing this behaviour, would be for cfmNavigation
to access the Splitter control directly, so that the NodeClick event for the
TreeView would look like:
Private Sub
TreeView1_NodeClick(ByVal Node As MSComctlLib.Node)
'Set the Active Page based on which node was clicked.
Select Case Node.Key
Case "About"
Set
frmMain.Splitter1.ChildForm2 = cfmAbout
Case "Page1"
Set
frmMain.Splitter1.ChildForm2 = cfmPage1
Case "Page2"
Set
frmMain.Splitter1.ChildForm2 = cfmPage2
End Select
End Sub |
|