Advertisement
Guest User

Untitled

a guest
May 5th, 2015
204
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.97 KB | None | 0 0
  1. treeView.ImageKey = "Value";
  2. Debug.WriteLine(treeView.ImageIndex);
  3. treeView.ImageKey = null;
  4. Debug.WriteLine(treeView.ImageIndex);
  5. treeView.ImageIndex = -1;
  6. Debug.WriteLine(treeView.ImageIndex);
  7.  
  8. -1
  9. 0
  10. 0
  11.  
  12. TreeNode node1 = new TreeNode(string.Empty, 12, 12); // imageList1.Count = 5
  13.  
  14. if (e.Node.ImageIndex >= e.Node.TreeView.ImageList.Images.Count) // if there is no image
  15. {
  16. int imagewidths = e.Node.TreeView.ImageList.ImageSize.Width;
  17. int textheight = TextRenderer.MeasureText(e.Node.Text, e.Node.NodeFont).Height;
  18. int x = e.Node.Bounds.Left - 3 - imagewidths / 2;
  19. int y = (e.Bounds.Top + e.Bounds.Bottom) / 2+1;
  20.  
  21. Point point = new Point(x - imagewidths/2, y - textheight/2); // the new location for the text to be drawn
  22.  
  23. TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.NodeFont, point, e.Node.ForeColor);
  24. }
  25. else // drawn at the default location
  26. TextRenderer.DrawText(e.Graphics, e.Node.Text, e.Node.TreeView.Font, e.Bounds, e.Node.ForeColor);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement