Private Sub UserForm_Initialize() '初始化ImageList控件,添加图片 Dim img As New ImageList img.ListImages.Add 1, "book1", LoadPicture(ThisWorkbook.Path & "\book1.gif") img.ListImages.Add 2, "book2", LoadPicture(ThisWorkbook.Path & "\book2.gif") img.ListImages.Add 3, "book3", LoadPicture(ThisWorkbook.Path & "\book3.gif") Set TreeView1.ImageList = img '设置显示节点路径时的分隔符 TreeView1.PathSeparator = "\" End Sub 复制代码 Private Sub CommandButton1_Click() Dim nodex As Node TreeView1.Nodes.Clear '添加节点 Set nodex = TreeView1.Nodes.Add(, , "研究院", "研究院", "book1") Set nodex = TreeView1.Nodes.Add("研究院", tvwChild, "汇智", "汇智", "book2") Set nodex = TreeView1.Nodes.Add("研究院", tvwChild, "众智", "众智", "book2") Set nodex = TreeView1.Nodes.Add("研究院", tvwChild, "星汇", "星汇", "book2") Set nodex = TreeView1.Nodes.Add("研究院", tvwChild, "亿迅", "亿迅", "book2") Set nodex = TreeView1.Nodes.Add("研究院", tvwChild, "普信", "普信", "book2") End Sub 复制代码 Private Sub CommandButton2_Click() '设置复选框显示 TreeView1.CheckBoxes = True End Sub 复制代码 Private Sub CommandButton3_Click() '清除节点 TreeView1.Nodes.Clear End Sub 复制代码 Private Sub CommandButton4_Click() '去除复选框 TreeView1.CheckBoxes = False End Sub 复制代码 Private Sub CommandButton5_Click() '开启热跟踪功能 TreeView1.HotTracking = True End Sub 复制代码 Private Sub CommandButton6_Click() '编辑节点 TreeView1.StartLabelEdit End Sub 复制代码 Private Sub CommandButton7_Click() '显示根节点连线 TreeView1.LineStyle = tvwRootLines End Sub 复制代码 Private Sub CommandButton8_Click() '隐藏根节点连线 TreeView1.LineStyle = tvwTreeLines End Sub 复制代码 Private Sub CommandButton9_Click() '若所选为根节点,将其子节点连线一起去除 TreeView1.Nodes.Remove TreeView1.SelectedItem.Index End Sub 复制代码 Private Sub CommandButton10_Click() '统计节点个数 Label1.Caption = "TreeView控件中节点对象的个数为:" & TreeView1.Nodes.Count & "个" End Sub 复制代码 Private Sub CommandButton11_Click() '所选节点显示为粗体 TreeView1.SelectedItem.Bold = True End Sub 复制代码 Private Sub CommandButton12_Click() '展开所有节点 Dim i As Long For i = 1 To TreeView1.Nodes.Count TreeView1.Nodes(i).Expanded = True Next i End Sub 复制代码 Private Sub CommandButton13_Click() '折叠所有节点 Dim i As Long For i = 1 To TreeView1.Nodes.Count TreeView1.Nodes(i).Expanded = False Next i End Sub 复制代码 Private Sub OptionButton1_Click() '节点仅为文本 TreeView1.Style = tvwTextOnly End Sub 复制代码 Private Sub OptionButton2_Click() '节点仅为图像 TreeView1.Style = tvwPictureText End Sub 复制代码 Private Sub OptionButton3_Click() '节点为符号文本 TreeView1.Style = tvwPlusMinusText End Sub 复制代码 Private Sub OptionButton4_Click() '为直线文本 TreeView1.Style = tvwTreelinesText End Sub 复制代码 Private Sub OptionButton5_Click() '节点显示恢复正常 TreeView1.Style = tvwTreelinesPlusMinusText End Sub 复制代码 Private Sub TreeView1_NodeClick(ByVal Node As MSComctlLib.Node) '返回对象路径 Label2.Caption = Node.FullPath End Sub 复制代码