是否可以在不使用ImageList的情况下将图像添加到树视图节点?

时间:2023-01-30 18:03:32

(Using WinForms and C#. -> .Net 2.0)

(使用WinForms和C#。 - > .Net 2.0)

I am adding nodes to a TreeView based on data in a table. As well as the caption to appear on the node, that data also contains Bitmaps.

我正在基于表中的数据向TreeView添加节点。除了显示在节点上的标题外,该数据还包含位图。

I would like to use the Bitmap from the table as the icon on the TreeViewNode, not one from a pre-existing ImageList. (Normally you designate a Key or an Index of an image in an image list to set the node's image.)

我想使用表中的Bitmap作为TreeViewNode上的图标,而不是来自预先存在的ImageList的图标。 (通常,您可以在图像列表中指定图像的键或索引来设置节点的图像。)

Is this possible or do I need to add the Bitmap from my data to the ImageList (at runtime) then use that ImageList to populate the image on the node.

这是可能的还是我需要将我的数据中的位图添加到ImageList(在运行时),然后使用该ImageList填充节点上的图像。

1 个解决方案

#1


I think you have two options. You can populate an ImageList from your data like you're suggesting, or you can draw the image onto the control yourself (with the Paint event).

我想你有两个选择。您可以像您建议的那样从数据中填充ImageList,也可以自己将图像绘制到控件上(使用Paint事件)。

#1


I think you have two options. You can populate an ImageList from your data like you're suggesting, or you can draw the image onto the control yourself (with the Paint event).

我想你有两个选择。您可以像您建议的那样从数据中填充ImageList,也可以自己将图像绘制到控件上(使用Paint事件)。