Tree stall

I have implemented a multi-color system for each of my TreeView nodes. But every time I expand the child of a node, it consumes and also draws a node on top of my rootNode (images 2 and 3). The code is from my previous question , and here is what the error looks like:

enter image description here

If I decided to close each node and deploy the glitch again, it disappeared. (figure 4)

Problem. It seems with Bounds why a draw is not in 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); } } } 
+6
source share
1 answer

The drawing looks like an accurate description.

You can try this work by signing up for the AfterExpand event:

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

All Articles