Treeview画的故障 [英] Treeview draw glitch

查看:135
本文介绍了Treeview画的故障的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我为每个 TreeView 节点实现了一个多色系统。但每次我展开一个子节点,它花费,但也描绘我的根节点上的节点(图像2和3)。代码来自我上一个问题,这是错误的样子



>



如果我决定关闭每个节点并重新展开毛刺已经消失了。(image 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))
{
使用(画笔刷= new SolidBrush(Color.Red))
{
e.Graphics.DrawString(texts [0],font,brush,e.Bounds.Left,e.Bounds.Top);
}

使用(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);
}
}
}


解决方案>

绘制毛刺似乎是一个准确的描述。



您可以通过订阅AfterExpand事件来尝试这个工作:

  void treeView1_AfterExpand(object sender,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();
}

这篇关于Treeview画的故障的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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