TreeView控件与多色树节点的文本 [英] TreeView with multi-color TreeNode text

查看:172
本文介绍了TreeView控件与多色树节点的文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在TreeView的一个节点中的文本进行文字或字符内的颜色。那可能吗?什么是要走的路?我听说自定义绘图的,但没有经验与它

I need to have the text within a node in TreeView to be colored within words or characters. Is that possible? What is the way to go? I heard of Custom Drawing but have no experience with it!

推荐答案

设置TreeView控件的属性:

Set the property of the TreeView:

treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;



然后,从DrawNode事件:

Then from the DrawNode event:

private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e) {
  Color nodeColor = Color.Red;
  if ((e.State & TreeNodeStates.Selected) != 0)
    nodeColor = SystemColors.HighlightText;

  TextRenderer.DrawText(e.Graphics,
                        e.Node.Text,
                        e.Node.NodeFont,
                        e.Bounds,
                        nodeColor,
                        Color.Empty,
                        TextFormatFlags.VerticalCenter);
}



从MSDN更多:的 TreeView.DrawNode事件

这篇关于TreeView控件与多色树节点的文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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