'This property needs to be set in the from_activate event
'If set in the form_load event, the tree won't populate.
MhTree1.SingleSelect = True
'Calls the routine to expand the tree
itmList_Click
'This tells tells the tree to expand all the columns
'Substituting any legitimate column number for -1 would
'tell the tree to expand to the column specified
MhTree1.Expand = MhTree1.Columns - 1
MhTree1.SetFocus
End Sub
Private Sub Form_Load()
'Because this is an example, all of the properties
'that are not specifically designtime properties suc
'as the name are set through code.
'Set defaults for the form
fMhTree.Caption = "MicroHelp MhTree Example"
'Set properties for the tree
MhTree1.Left = 20
MhTree1.Top = 30
MhTree1.Width = 3090
MhTree1.Height = 5350
'Set properties of command button
cmdAddSelect.Caption = "&Add Selected Item To Group One"
'Set properties for labels
lblSelect.Caption = "Items in Group One"
lblTree.BevelSize = 2
lblXplain.Caption = "One of the most powerful aspects of the tree is the control's capacity to add items to different groups and set properties to affect only that group. For an illustration, select an item from the tree, click " & Chr$(34) & "Add To Group One" & Chr$(34) & " and then set the Group One color properties to see how you can address the group as a whole."
lblMoreXplain.Caption = "Note that the tree can be navigated by double-clicking with the mouse or by pressing the Spacebar when the selected item is a folder. Use the arrow keys to navigate up or down. It's great for building File Manager or Windows Explorer-style applications."
End Sub
Private Sub itmAddItem_Click()
'This uses the .AddItem method to load some items in the MhTree1
'AddItem is a good choice for dynamically loading the box because
'each item will be displayed as it is loaded.
'This is a property that emulates the Clear method. We use it here
'so that we can put items in the tree.
MhTree1.ClearBox = 0
'Sets the list count and makes sure the filelist is not loaded.
MhTree1.FileList = False
MhTree1.DefaultPics = True
MhTree1.ListCount = 50
'For every branch off the trunk of the tree, a column must be declared
'Then set the address to the particular column whose properties you want
'to change.
MhTree1.Columns = 4
MhTree1.Column = 0
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(1)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(3)
MhTree1.Column = 1
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(1)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(3)
MhTree1.Column = 2
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
MhTree1.Column = 3
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
MhTree1.Column = 4
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
'The tree always has a dummy item in it so we remove it.
MhTree1.RemoveItem 0
'This creates the first folder. First the column is addressed, then it is added,
'then the item is added. Note the .AddItem method requires that an index
'This will set a bevel size based on the user's choice
Dim iIndex As Integer
'Uncheck menu items
For iIndex = 0 To 2
itmBevel(iIndex).Checked = False
Next
'Make selection and check menu. We change color to highlight the selection
'so it will be easier to see now that the bevel is removed. We do the refresh
'in case the user has a currently selected item. We want that item to
'reflect the change they've made.
Select Case Index
Case im_NONE
itmStyle(0).Checked = False
itmStyle(1).Checked = False
MhTree1.BevelSizeInner = im_NONE
MhTree1.FillColor = im_WHITE
MhTree1.SelectedColor = &H8000000D
MhTree1.Refresh
'Value chosen because it looks best. Change .SelectedColor so visual effect
'of bevel will be highlighted
Case im_SMALL
MhTree1.BevelSizeInner = 2
itmStyle(im_LOWERED).Checked = True
MhTree1.FillColor = &HC0C0C0
MhTree1.SelectedColor = &HC0C0C0
MhTree1.Refresh
'Value best illustrates .LightColor, .ShadowColor properties
Case im_LARGE
MhTree1.BevelSizeInner = 5
itmStyle(im_RAISED).Checked = True
MhTree1.FillColor = &HC0C0C0
MhTree1.SelectedColor = &HC0C0C0
MhTree1.Refresh
End Select
itmBevel(Index).Checked = True
End Sub
Private Sub itmColColor_Click(Index As Integer)
'Routine calls up common color dialog so we can
'illustrate the color properties of the control.
MhTree1.Column = 1
'Sets flag to prevent custom color palette from
'appearing, calls dialog and sets appropriate
'color property when dialog closes.
MhCommonDialog1.Flags = CC_PREVENTFULLOPEN
MhCommonDialog1.CancelError = True
On Error GoTo ColColorError
MhCommonDialog1.Action = 3
Select Case Index
Case im_COLBACKCOLOR
MhTree1.ColBackColor = MhCommonDialog1.Color
Case im_COLFORECOLOR
MhTree1.ColForeColor = MhCommonDialog1.Color
Case im_COLHIGHCOLOR
MhTree1.ColHighColor = MhCommonDialog1.Color
End Select
Exit Sub
ColColorError:
Select Case Index
Case im_COLBACKCOLOR
MhTree1.ColBackColor = MhTree1.ColBackColor
Case im_COLFORECOLOR
MhTree1.ColForeColor = MhTree1.ColForeColor
Case im_COLHIGHCOLOR
MhTree1.ColHighColor = MhTree1.ColHighColor
End Select
Exit Sub
End Sub
Private Sub itmDirectory_Click()
'This will place a list of all the directories
'on your disk in the MhTree1. As always, first we clear the MhTree1,
'then set ListCount.
MhTree1.ClearBox = 0
MhTree1.ListCount = 1000
ChDir "c:\"
MhTree1.Dir = True
'This causes the box to list the directories
MhTree1.FileList = True
'This causes the current directory to appear as the trunk of the MhTree1
MhTree1.List(0) = CurDir
End Sub
Private Sub itmExit_Click()
'Dump form, end
Unload fMhTree
End
End Sub
Private Sub itmGlobalColor_Click(Index As Integer)
'Routine calls up common color dialog so we can
'illustrate the color properties of the control.
'Sets flag to prevent custom color palette from
'appearing, calls dialog and sets appropriate
'color property when dialog closes.
MhCommonDialog1.Flags = CC_PREVENTFULLOPEN
MhCommonDialog1.CancelError = True
On Error GoTo ColorError
MhCommonDialog1.Action = 3
Select Case Index
Case im_BORDERCOLOR
MhTree1.BorderColor = MhCommonDialog1.Color
Case im_FILLCOLOR
MhTree1.FillColor = MhCommonDialog1.Color
Case im_HIGHCOLOR
MhTree1.HighColor = MhCommonDialog1.Color
Case im_LIGHTCOLOR
MhTree1.LightColor = MhCommonDialog1.Color
Case im_LINECOLOR
MhTree1.LineColor = MhCommonDialog1.Color
Case im_SELECTEDCOLOR
MhTree1.SelectedColor = MhCommonDialog1.Color
Case im_SHADOWCOLOR
MhTree1.ShadowColor = MhCommonDialog1.Color
Case im_TEXTCOLOR
MhTree1.TextColor = MhCommonDialog1.Color
End Select
Exit Sub
ColorError:
Select Case Index
Case im_BORDERCOLOR
MhTree1.BorderColor = MhTree1.BorderColor
Case im_FILLCOLOR
MhTree1.FillColor = MhTree1.FillColor
Case im_HIGHCOLOR
MhTree1.HighColor = MhTree1.HighColor
Case im_LIGHTCOLOR
MhTree1.LightColor = MhTree1.LightColor
Case im_LINECOLOR
MhTree1.LineColor = MhTree1.LineColor
Case im_SELECTEDCOLOR
MhTree1.SelectedColor = MhTree1.SelectedColor
Case im_SHADOWCOLOR
MhTree1.ShadowColor = MhTree1.ShadowColor
Case im_TEXTCOLOR
MhTree1.TextColor = MhTree1.TextColor
End Select
Exit Sub
End Sub
Private Sub itmGroupColor_Click(Index As Integer)
'Routine calls up common color dialog so we can
'illustrate the color properties of the control.
If lstSelect.ListCount = 0 Then
MsgBox "These properties cannot be set until Group One is created. Select an item from the list and Click the " & Chr$(34) & "Add To Group One" & Chr$(34) & " button before trying to set these properties.", 16, "MicroHelp"
Exit Sub
End If
MhTree1.Group = 1
'Sets flag to prevent custom color palette from
'appearing, calls dialog and sets appropriate
'color property when dialog closes.
MhCommonDialog1.Flags = CC_PREVENTFULLOPEN
MhCommonDialog1.CancelError = True
On Error GoTo GroupColorError
MhCommonDialog1.Action = 3
Select Case Index
Case im_GROUPBACKCOLOR
MhTree1.GroupBackColor = MhCommonDialog1.Color
Case im_GROUPFORECOLOR
MhTree1.GroupForeColor = MhCommonDialog1.Color
Case im_GROUPHIGHCOLOR
MhTree1.GroupHighColor = MhCommonDialog1.Color
End Select
Exit Sub
GroupColorError:
Select Case Index
Case im_GROUPBACKCOLOR
MhTree1.GroupBackColor = MhTree1.GroupBackColor
Case im_GROUPFORECOLOR
MhTree1.GroupForeColor = MhTree1.GroupForeColor
Case im_GROUPHIGHCOLOR
MhTree1.GroupHighColor = MhTree1.GroupHighColor
End Select
Exit Sub
End Sub
Private Sub itmList_Click()
'The .List method populates the box also. Unlike the .AddItem method, the list
'will appear with only the root showing as opposed to showing every branch of
'the MhTree1.
'The .ClearBox property acts like a method to clear the box if set to 0
'Note, also, that .ListCount MUST be set prior to populating the tree. This
'is not the usual listbox property. It doesn't return info about how many items
'are in the tree; It sets a limit on how many items the tree can contain.
MhTree1.ClearBox = 0
MhTree1.ListCount = 100
MhTree1.DefaultPics = True
'You MUST set the number of columns and the widths of those columns.
'It's easiest to set the pictures for selected and unselected states
'on a per-column basis at the beginning of your routine. That way, you
'don't have to worry about setting each one.
'Note that this could also be done on a per-line basis using .ListPicture
'That's illustrated below.
MhTree1.Columns = 5
MhTree1.Column = 0
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(1)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(3)
MhTree1.Column = 1
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(1)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(3)
MhTree1.Column = 2
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
MhTree1.Column = 3
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
MhTree1.Column = 4
MhTree1.ColWidth = 10
MhTree1.ColPicture = MhTree1.Loadedpicture(5)
MhTree1.ColPictureSel = MhTree1.Loadedpicture(7)
'The following pattern is repeated over and over again.
'This sets the index and caption to 0
MhTree1.List(0) = "MhTree1 trunk"
'This adds the item at index 0 and puts it in column 0
MhTree1.ListColumn(0) = 0
'Notice now all values change to 1 because we move to index 1 and column 1
MhTree1.List(1) = "Branch 1 of trunk"
MhTree1.ListColumn(1) = 1
'Now all values change to 2 because we move to index 2 and column 2
MhTree1.List(2) = "Sub Branch 1"
MhTree1.ListColumn(2) = 2
'Now index changes to 3 but column remains at 2 because we're in the same column
'as the previous item.
MhTree1.List(3) = "Sub Branch 2"
MhTree1.ListColumn(3) = 2
MhTree1.List(4) = "Sub Branch 3"
MhTree1.ListColumn(4) = 2
MhTree1.List(5) = "Branch 2 of trunk"
MhTree1.ListColumn(5) = 1
MhTree1.List(6) = "Sub Branch 3"
MhTree1.ListColumn(6) = 2
MhTree1.List(7) = "Sub Branch 4"
MhTree1.ListColumn(7) = 2
'Here, we're adding some branches off this sub branch so we have
'change it's picture on a per-line basis since we want the rest of
'the items to have the default document-type artwork.