using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace test28
{
public class TreeViewMouseOver : TreeView
{
private TreeNode overNode;
protected override void OnMouseMove(MouseEventArgs e)
{
base.OnMouseMove(e);
TreeNode n = this.GetNodeAt(this.PointToClient(Control.MousePosition));
if (n != overNode)
{
if (overNode != null)
{
this.Invalidate(overNode.Bounds);
}
overNode = n;
this.Invalidate(n.Bounds);
}
}
protected override void OnDrawNode(DrawTreeNodeEventArgs e)
{
if (e.Node == overNode)
{
e.Graphics.FillRectangle(Brushes.Red, e.Bounds);
}
TextRenderer.DrawText(e.Graphics, e.Node.Text, this.Font, e.Bounds, Color.Black, TextFormatFlags.GlyphOverhangPadding);
}
}
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
TreeViewMouseOver tv = new TreeViewMouseOver();
tv.Dock = DockStyle.Fill;
tv.DrawMode = TreeViewDrawMode.OwnerDrawText;
for (int i = 0; i < 100; i++)
{
tv.Nodes.Add("node" + i.ToString());
}
this.Controls.Add(tv);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRGF0YTsKdXNpbmcgU3lzdGVtLkRyYXdpbmc7CnVzaW5nIFN5c3RlbS5MaW5xOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7CgpuYW1lc3BhY2UgdGVzdDI4CnsKICAgIHB1YmxpYyBjbGFzcyBUcmVlVmlld01vdXNlT3ZlciA6IFRyZWVWaWV3CiAgICB7CiAgICAgICAgcHJpdmF0ZSBUcmVlTm9kZSBvdmVyTm9kZTsKICAgICAgICBwcm90ZWN0ZWQgb3ZlcnJpZGUgdm9pZCBPbk1vdXNlTW92ZShNb3VzZUV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgYmFzZS5Pbk1vdXNlTW92ZShlKTsKICAgICAgICAgICAgVHJlZU5vZGUgbiA9IHRoaXMuR2V0Tm9kZUF0KHRoaXMuUG9pbnRUb0NsaWVudChDb250cm9sLk1vdXNlUG9zaXRpb24pKTsKICAgICAgICAgICAgaWYgKG4gIT0gb3Zlck5vZGUpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIGlmIChvdmVyTm9kZSAhPSBudWxsKQogICAgICAgICAgICAgICAgewogICAgICAgICAgICAgICAgICAgIHRoaXMuSW52YWxpZGF0ZShvdmVyTm9kZS5Cb3VuZHMpOwogICAgICAgICAgICAgICAgfQogICAgICAgICAgICAgICAgb3Zlck5vZGUgPSBuOwogICAgICAgICAgICAgICAgdGhpcy5JbnZhbGlkYXRlKG4uQm91bmRzKTsKICAgICAgICAgICAgfQogICAgICAgIH0KICAgICAgICBwcm90ZWN0ZWQgb3ZlcnJpZGUgdm9pZCBPbkRyYXdOb2RlKERyYXdUcmVlTm9kZUV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgaWYgKGUuTm9kZSA9PSBvdmVyTm9kZSkKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgZS5HcmFwaGljcy5GaWxsUmVjdGFuZ2xlKEJydXNoZXMuUmVkLCBlLkJvdW5kcyk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgVGV4dFJlbmRlcmVyLkRyYXdUZXh0KGUuR3JhcGhpY3MsIGUuTm9kZS5UZXh0LCB0aGlzLkZvbnQsIGUuQm91bmRzLCBDb2xvci5CbGFjaywgVGV4dEZvcm1hdEZsYWdzLkdseXBoT3ZlcmhhbmdQYWRkaW5nKTsKICAgICAgICB9CiAgICAgICAgCiAgICB9CgogICAgcHVibGljIHBhcnRpYWwgY2xhc3MgRm9ybTEgOiBGb3JtCiAgICB7CiAgICAgICAgcHVibGljIEZvcm0xKCkKICAgICAgICB7CiAgICAgICAgICAgIEluaXRpYWxpemVDb21wb25lbnQoKTsKICAgICAgICB9CgogICAgICAgIHByaXZhdGUgdm9pZCBGb3JtMV9Mb2FkKG9iamVjdCBzZW5kZXIsIEV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgVHJlZVZpZXdNb3VzZU92ZXIgdHYgPSBuZXcgVHJlZVZpZXdNb3VzZU92ZXIoKTsKICAgICAgICAgICAgdHYuRG9jayA9IERvY2tTdHlsZS5GaWxsOwogICAgICAgICAgICB0di5EcmF3TW9kZSA9IFRyZWVWaWV3RHJhd01vZGUuT3duZXJEcmF3VGV4dDsKICAgICAgICAgICAgZm9yIChpbnQgaSA9IDA7IGkgPCAxMDA7IGkrKykKICAgICAgICAgICAgewogICAgICAgICAgICAgICAgdHYuTm9kZXMuQWRkKCJub2RlIiArIGkuVG9TdHJpbmcoKSk7CiAgICAgICAgICAgIH0KICAgICAgICAgICAgdGhpcy5Db250cm9scy5BZGQodHYpOwogICAgICAgIH0KICAgIH0KfQo=