
Private Sub UserForm_Initialize()
Dim img As New ImageList
img.ListImages.Add 1, "book1", LoadPicture(ThisWorkbook.Path & "\book1.jpg")
img.ListImages.Add 2, "book2", LoadPicture(ThisWorkbook.Path & "\book2.jpg")
img.ListImages.Add 3, "book3", LoadPicture(ThisWorkbook.Path & "\book3.jpg")
Set TreeView1.ImageList = img '链接图像列
TreeView1.LineStyle = tvwTreeLines '在兄弟节点和根节点之间显示线
'树状外观包含全部元素
TreeView1.Style = tvwTreelinesPlusMinusPictureText
'建立名称为"VBA控件"的父节点,选择索引为1的图像
Set nodx = TreeView1.Nodes.Add(, , "VBA控件", "VBA控件", 1)
'在"VBA控件"根节点下建立"第一章"子节点,选择索引为3的图像
Set nodx = TreeView1.Nodes.Add("VBA控件", tvwChild, "child01", "第一章", 3)
'在"VBA控件"根节点下建立"第二章"子节点,选择索引为3的图像
Set nodx = TreeView1.Nodes.Add("VBA控件", tvwChild, "child02", "第二章", 3)
b = False
End Sub
Private Sub CommandButton1_Click()
If TextBox1.Text <> "" And TextBox2.Text <> "" Then
'不允许建立零字节的根节点和子节点
b = False
j = TreeView1.Nodes.Count
For i = 1 To TreeView1.Nodes.Count '检查新输入的根节点名称是否存在
If TreeView1.SelectedItem.Children > 0 Then
If TextBox1.Text = TreeView1.Nodes(i).Text Then b = True
End If
Next i
If b = True Then '若存在, 则在根节点下建立子节点
Set nodx = TreeView1.Nodes.Add(TextBox1.Text, tvwChild, "child" & j, TextBox2.Text, 3)
Else '若不存在,则建立根节点和子节点
Set nodx = TreeView1.Nodes.Add(, , TextBox1.Text, TextBox1.Text, 1)
Set nodx = TreeView1.Nodes.Add(TextBox1.Text, tvwChild, "child" & j, TextBox2.Text, 3)
End If
TreeView1.Refresh
ElseIf TextBox1.Text = "" Then MsgBox "请输入根节点名称!", vbInformation, "警告!"
'系统提示
ElseIf TextBox2.Text = "" Then MsgBox "请输入子节点名称!", vbInformation, "警告!"
End If
End Sub
Private Sub CommandButton2_Click()
For i = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(i).Expanded = True '展开所有节点
Next i
End Sub
Private Sub CommandButton3_Click()
For i = 1 To TreeView1.Nodes.Count
TreeView1.Nodes(i).Expanded = False'折叠所有节点
Next i
End Sub
Private Sub CommandButton4_Click()
TreeView1.Sorted = True '排列顺序
End Sub
Private Sub CommandButton5_Click()
If TreeView1.SelectedItem.Index <> 1 Then
TreeView1.Nodes.Remove TreeView1.SelectedItem.Index '删除选定的节点
End If
End Sub
Private Sub CommandButton6_Click()
End '退出程序
End Sub
Private Sub TreeView1_Expand(ByVal Node As MSComctlLib.Node)
Node.ExpandedImage = 2 '节点被展开时,选择索引为2的图像
End Sub


声明:欢迎各大网站转载本站文章,还请保留一条能直接指向本站的超级链接,谢谢!
第1页 | 第2页 | 第3页 | 第4页 | 第5页 | 第6页 | 第7页时间:2007-9-26 21:11:51,点击:0
上一篇:在office Excel页眉页脚中插入图片【声明】:以上文章或资料除注明为Office吧自创或编辑整理外,均为各方收集或网友推荐所得。其中摘录的内容以共享、研究为目的,不存在任何商业考虑。如有任何异议,请与本站联系,联系邮箱:thinkou@126.com,本站确认后将立即撤下。谢谢您的支持与理解!
相关评论