【问题标题】:Concat text of treeview node with image树视图节点的文本与图像的连接
【发布时间】:2019-05-03 02:43:58
【问题描述】:

我在 windows 窗体中有带有三个视图节点的树视图

我想知道是否可以将文本与图像连接起来。我是说

注意:图片当前存储在ImageList

This is a node (image here)
Another node (image here)

我尝试做类似的事情:

nodes[idx].Text = nodes[idx].Text + nodes[idx].ImageIndex;

但它只是做这样的事情:

 This is a node 10
 Another node 10

而不是使用图像,它使用当前图像索引值。

有没有可能实现我想要的?

【问题讨论】:

  • 所以你想连接字符串和字节?
  • 我不知道 ImageCollection 是否返回字节,但我再次尝试:nodes[idx].Text = nodes[idx].Text + imgList.Images[1]; 并返回 This is a node System.Drawing.Bitmap@HastaTamang
  • 您正带着这个要求进入 OwnerDraw 和 DrawNode 世界。
  • 对使用标准功能有什么反感 - docs.microsoft.com/en-us/dotnet/framework/winforms/controls/… - 图标在左侧是个大问题吗?
  • 我想在文本旁边创建类似“标签”的内容,因此根据收到的值设置标签,例如“已审核”-“已完成”等。@CaiusJard

标签: c# winforms


【解决方案1】:

我认为您想要实现的目标并不是那么容易实现的。 text 属性只能包含一个文本字符串。

实现这一点的一种可能性是使用所有者绘制的树视图。这个很复杂,需要自己实现完整的文字绘制和图像绘制。例如,您可以在以下问题中找到更多信息:

TreeView with custom drawn TreeNode

How to add icons to TreeView control in c# using OnPaint args

如果您只想显示特定的标准图标,更简单的解决方案可能是使用 unicode 图标。

        treeView1.Nodes.Add("go to LA ✈");
        var n = treeView1.Nodes.Add("Tasks ❒");
        n.Nodes.Add("Done ✅");
        n.Nodes.Add("Failed ❎");

您可以在不同的页面上找到一个符号列表,例如 https://en.wikipedia.org/wiki/Dingbat#Unicode

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2013-11-26
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多