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. TreeNode n = this.GetNodeAt(this.PointToClient(Control.MousePosition));
  18. if (n != overNode)
  19. {
  20. overNode = n;
  21. this.Invalidate();
  22. }
  23. base.OnMouseMove(e);
  24. }
  25. protected override void OnDrawNode(DrawTreeNodeEventArgs e)
  26. {
  27. if (e.Node == overNode)
  28. {
  29. e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
  30. }
  31. TextRenderer.DrawText(e.Graphics, e.Node.Text, this.Font, e.Bounds, Color.Black, TextFormatFlags.GlyphOverhangPadding);
  32. }
  33. }
  34.  
  35. public partial class Form1 : Form
  36. {
  37. public Form1()
  38. {
  39. InitializeComponent();
  40. }
  41.  
  42. private void Form1_Load(object sender, EventArgs e)
  43. {
  44. TreeViewMouseOver tv = new TreeViewMouseOver();
  45. tv.Dock = DockStyle.Fill;
  46. tv.DrawMode = TreeViewDrawMode.OwnerDrawText;
  47. for (int i = 0; i < 100; i++)
  48. {
  49. tv.Nodes.Add("node" + i.ToString());
  50. }
  51. this.Controls.Add(tv);
  52. }
  53. }
  54. }
  55.  
Not running #stdin #stdout 0s 0KB
stdin
Standard input is empty
stdout
Standard output is empty