在TreeView控件添加图片 [英] add image in treeView

查看:758
本文介绍了在TreeView控件添加图片的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

TreeNode desktop = new TreeNode();
desktop.Text = "Desktop";
desktop.Tag = "Desktop";
Mycomputer.ImageIndex = 1;
Mycomputer.SelectedImageIndex = 1;
desktop.Nodes.Add("");
treeView1.Nodes.Add(desktop);

TreeNode Mycomputer = new TreeNode("My Computer");
Mycomputer.ImageIndex = 1;
Mycomputer.SelectedImageIndex = 1;
treeView1.Nodes.Add(Mycomputer);



我现在用的是的ImageIndex 属性,但在这里是的形象呢?

I am using the ImageIndex property but where is the image?

我如何选择我的形象和来自哪里?

How do I choose my image and from where?

推荐答案

有关的ImageIndex 有任何意义,你的树视图中应该有一个指定的的ImageList 。在的ImageIndex 属性是指图像列表的要呈现的图像内的索引。

For ImageIndex to have any meaning, your tree view should have an ImageList assigned. The ImageIndex property refers to the index within the image list of the image you want to present.

您可以创建一个的ImageList 手动,或通过设计师。这个例子演示了创建并分配一个的ImageList 手动的方法:

You can create an ImageList manually, or via the designer. This example demonstrates a method of creating and assigning an ImageList manually:

http://msdn.microsoft.com/en-us/library/system.windows.forms.treeview.imagelist的.aspx

对于我来说,我只是突然打开设计,选择树视图中,找到在属性编辑器ImageList属性,然后单击它启动。一个弹出窗口,让我来选择并导入一组成为图像列表资源

For me, I just pop open the designer, select the tree view, find the ImageList property in the property editor, and click it to launch a popup window that allows me to select and import a set of resources that become the image list.

下面是过程的一些截图:

Here are some screenshots of the process:

ImageList组件可以拖动到窗体从工具箱

The ImageList component can be dragged onto your form from the toolbox.

它有它的特性中的图像集合。

It has an Images collection among its properties.

通过对图像列表的形式,你可以选择它为您的树视图ImageList属性。

With the image list on the form, you can select it for the ImageList property on your tree view.

Screen03

我希望帮助填补一些空白。

I hope that helps fill some of the gaps.

祝你好运!

这篇关于在TreeView控件添加图片的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆