我需要让TreeView的节点内的文本在单词或字符内着色。那可能吗?怎么走?我听说过“自定义图纸”,但没有经验!
最佳答案
设置TreeView的属性:
treeView1.DrawMode = TreeViewDrawMode.OwnerDrawText;
然后从DrawNode事件:
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 Event