我需要让TreeView中的节点内的文本在单词或字符中着色。那可能吗?怎么走?我听说过自定义绘图但没有经验!
答案 0 :(得分:6)
设置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