vb6.0 如何在TreeView控件节点前加一个不同的图标

vb6.0 如何在TreeView控件节点前加一个不同的图标,第1张

首先,添加部件“Microsoft

Windows

Common

Controls

6.0”.添加控件Treeview1,Imagelist1.注意,Treeview添加图标必须通过Imagelist控件的辅助来进行。然后右击Imagelist1,选择属性,在里面的对话框中选择Image选项卡,单击Insert

Image

按钮,找到你需要的图标,全部导入。我以VB的Common文件夹中的Graphics\Icons\Comm中的图标为例。代码如下。

===============

Option

Explicit

Private

Sub

Form_Load()

Dim

i

As

Integer

TreeView1.ImageList

=

ImageList1

For

i

=

1

To

ImageList1.ListImages.Count

TreeView1.Nodes.Add

Text:=i,

Image:=i

Next

End

Sub

树状结构使用treeview实现,控件添加方法:右击“工具箱”-“部件”-microsoft windows common controls 6.0-确定,应用

下面是简单的添加删除方法,

Option Explicit

‘添加项目

Private Sub Command1_Click()

Dim nodx As Node

Set nodx = TreeView1.Nodes.Add(, , "zf", "紫风无痕关系(双击收起)")

Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zfwife", "老婆")

Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zflover", "情人")

Set nodx = TreeView1.Nodes.Add("zf", tvwChild, "zffriend", "朋友")

Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp1", "大老婆")

Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp2", "二老婆")

Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp3", "三老婆")

Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp4", "四老婆")

Set nodx = TreeView1.Nodes.Add("zfwife", tvwChild, "lp5", "五老婆")

Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr1", "1号情人")

Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr2", "2号情人")

Set nodx = TreeView1.Nodes.Add("zflover", tvwChild, "qr3", "3号情人")

Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py1", "张三")

Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py2", "李四")

Set nodx = TreeView1.Nodes.Add("zffriend", tvwChild, "py3", "王麻子")

Set nodx = TreeView1.Nodes.Add("py1", tvwChild, "pylp1", "张三的老婆")

Set nodx = TreeView1.Nodes.Add("py1", tvwChild, "pylp2", "张三的孩子")

nodx.EnsureVisible

End Sub

'删除代码

Private Sub Command2_Click()

MsgBox ("将要删除" &TreeView1.SelectedItem.Text)

TreeView1.Nodes.Remove (TreeView1.SelectedItem.Index)

End Sub


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/bake/11843409.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-19
下一篇 2023-05-19

发表评论

登录后才能评论

评论列表(0条)

保存