树形平局毛刺 [英] Treeview draw glitch

查看:119
本文介绍了树形平局毛刺的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我实现了一个多色系统中为每个我的 TreeView控件节点。但每次我展开一个子节点,它消费也描绘了节点在我rootNode中(图像2和3)。该代码是从我刚才的问题,这是错误的样子。





如果我决定关闭每个节点并重新扩大故障消失。(图片4)



这个问题似乎是与边界这就是为什么平局是不是在正确的地方。
知道为什么吗?






 私人无效treeView1_DrawNode(对象发件人,DrawTreeNodeEventArgs E)
{
的String [] =文本e.Node.Text.Split();
使用(字体的字体=新字体(this.Font,FontStyle.Regular))
{使用
(刷刷=新SolidBrush(Color.Red))
{
e.Graphics.DrawString(文本[0],字体,画笔,e.Bounds.Left,e.Bounds.Top);使用
}

(刷刷=新SolidBrush(Color.Blue))
{
的SizeF S = e.Graphics.MeasureString(文本[0],字体);
e.Graphics.DrawString(文本[1],字体,刷子,e.Bounds.Left +(int)的s.Width,e.Bounds.Top);
}
}
}


解决方案

绘图故障似乎是一个准确的描述



您可以通过订阅AfterExpand事件围绕尝试这项工作:

 无效treeView1_AfterExpand(对象发件人,TreeViewEventArgs E){
treeView1.Invalidate();
}


I implemented a multicolor system for each of my TreeView nodes. But everytime I expand a child node, it expends but also paints the node over my rootNode (image 2 and 3). The code is from my previous question and this is what the bug looks like

If I decide to close every node and re-expand the glitch is gone.(image 4)

The problem Seems to be with the Bounds that's why the draw isn't at the right place. Any idea why ?


  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);
        }
    }
  }

解决方案

Drawing glitch seems to be an accurate description.

You can try this work around by subscribing to the AfterExpand event:

void treeView1_AfterExpand(object sender, TreeViewEventArgs e) {
  treeView1.Invalidate();
}

这篇关于树形平局毛刺的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆