TreeView控件与多色树节点的文本

编程入门 行业动态 更新时间:2024-10-23 05:03:28
本文介绍了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控件与多色树节点的文本

本文发布于:2023-11-09 15:47:11,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1572769.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:节点   控件   多色   文本   TreeView

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!