fork download
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace test28
  11. {
  12. public class TreeViewMouseOver : TreeView
  13. {
  14. private TreeNode overNode;
  15. protected override void OnMouseMove(MouseEventArgs e)
  16. {
  17. base.OnMouseMove(e);
  18. TreeNode n = this.GetNodeAt(this.PointToClient(Control.MousePosition));
  19. if (n != overNode)
  20. {
  21. if (overNode != null)
  22. {
  23. this.Invalidate(overNode.Bounds);
  24. }
  25. overNode = n;
  26. this.Invalidate(n.Bounds);
  27. }
  28. }
  29. protected override void OnDrawNode(DrawTreeNodeEventArgs e)
  30. {
  31. if (e.Node == overNode)
  32. {
  33. e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
  34. }
  35. TextRenderer.DrawText(e.Graphics, e.Node.Text, this.Font, e.Bounds, Color.Black, TextFormatFlags.GlyphOverhangPadding);
  36. }
  37.  
  38. }
  39.  
  40. public partial class Form1 : Form
  41. {
  42. public Form1()
  43. {
  44. InitializeComponent();
  45. }
  46.  
  47. private void Form1_Load(object sender, EventArgs e)
  48. {
  49. TreeViewMouseOver tv = new TreeViewMouseOver();
  50. tv.Dock = DockStyle.Fill;
  51. tv.DrawMode = TreeViewDrawMode.OwnerDrawText;
  52. for (int i = 0; i < 100; i++)
  53. {
  54. tv.Nodes.Add("node" + i.ToString());
  55. }
  56. this.Controls.Add(tv);
  57. }
  58. }
  59. }
  60.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty