【发布时间】:2012-11-29 07:06:00
【问题描述】:
我为每个TreeView 节点实现了一个多色系统。但是每次我扩展一个子节点时,它都会扩展,但也会在我的 rootNode 上绘制节点(图 2 和图 3)。代码来自my previous question,这就是错误的样子
如果我决定关闭每个节点并重新扩展,故障就消失了。(图 4)
问题似乎出在Bounds 上,这就是为什么抽签不在正确的地方。
知道为什么吗?
private void treeView1_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
string[] texts = e.Node.Text.Split();
using (Font font = new Font(this.Font, FontStyle.Regular))
{
using (Brush brush = new SolidBrush(Color.Red))
{
e.Graphics.DrawString(texts[0], font, brush, e.Bounds.Left, e.Bounds.Top);
}
using (Brush brush = new SolidBrush(Color.Blue))
{
SizeF s = e.Graphics.MeasureString(texts[0], font);
e.Graphics.DrawString(texts[1], font, brush, e.Bounds.Left + (int)s.Width, e.Bounds.Top);
}
}
}
【问题讨论】:
-
有意思...绘制节点时treeView1.DrawMode和e.Bounds.Left、e.Bounds.Top、s.Width的取值是多少?
-
drawMode 是 TreeViewDrawMode.OwnerDrawText
-
没错。我提到的变量的值是什么?
-
我无法检查值。我放了一个断点,所以每次我进入树视图它都会在我展开之前中断
-
除非你知道我可以在没有断点的情况下检查值
标签: c# winforms colors treeview