本文介绍了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控件与多色树节点的文本
发布评论