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)
{
TreeNode n = this.GetNodeAt(this.PointToClient(Control.MousePosition));
if (n != overNode)
{
overNode = n;
this.Invalidate();
}
base.OnMouseMove(e);
}
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);
}
}
}
dXNpbmcgU3lzdGVtOwp1c2luZyBTeXN0ZW0uQ29sbGVjdGlvbnMuR2VuZXJpYzsKdXNpbmcgU3lzdGVtLkNvbXBvbmVudE1vZGVsOwp1c2luZyBTeXN0ZW0uRGF0YTsKdXNpbmcgU3lzdGVtLkRyYXdpbmc7CnVzaW5nIFN5c3RlbS5MaW5xOwp1c2luZyBTeXN0ZW0uVGV4dDsKdXNpbmcgU3lzdGVtLldpbmRvd3MuRm9ybXM7CgpuYW1lc3BhY2UgdGVzdDI4CnsKICAgIHB1YmxpYyBjbGFzcyBUcmVlVmlld01vdXNlT3ZlciA6IFRyZWVWaWV3CiAgICB7CiAgICAgICAgcHJpdmF0ZSBUcmVlTm9kZSBvdmVyTm9kZTsKICAgICAgICBwcm90ZWN0ZWQgb3ZlcnJpZGUgdm9pZCBPbk1vdXNlTW92ZShNb3VzZUV2ZW50QXJncyBlKQogICAgICAgIHsKICAgICAgICAgICAgVHJlZU5vZGUgbiA9IHRoaXMuR2V0Tm9kZUF0KHRoaXMuUG9pbnRUb0NsaWVudChDb250cm9sLk1vdXNlUG9zaXRpb24pKTsKICAgICAgICAgICAgaWYgKG4gIT0gb3Zlck5vZGUpCiAgICAgICAgICAgIHsKICAgICAgICAgICAgICAgIG92ZXJOb2RlID0gbjsKICAgICAgICAgICAgICAgIHRoaXMuSW52YWxpZGF0ZSgpOwogICAgICAgICAgICB9CiAgICAgICAgICAgIGJhc2UuT25Nb3VzZU1vdmUoZSk7CiAgICAgICAgfQogICAgICAgIHByb3RlY3RlZCBvdmVycmlkZSB2b2lkIE9uRHJhd05vZGUoRHJhd1RyZWVOb2RlRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBpZiAoZS5Ob2RlID09IG92ZXJOb2RlKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICBlLkdyYXBoaWNzLkZpbGxSZWN0YW5nbGUoQnJ1c2hlcy5SZWQsIGUuQm91bmRzKTsKICAgICAgICAgICAgfQogICAgICAgICAgICBUZXh0UmVuZGVyZXIuRHJhd1RleHQoZS5HcmFwaGljcywgZS5Ob2RlLlRleHQsIHRoaXMuRm9udCwgZS5Cb3VuZHMsIENvbG9yLkJsYWNrLCBUZXh0Rm9ybWF0RmxhZ3MuR2x5cGhPdmVyaGFuZ1BhZGRpbmcpOwogICAgICAgIH0KICAgIH0KCiAgICBwdWJsaWMgcGFydGlhbCBjbGFzcyBGb3JtMSA6IEZvcm0KICAgIHsKICAgICAgICBwdWJsaWMgRm9ybTEoKQogICAgICAgIHsKICAgICAgICAgICAgSW5pdGlhbGl6ZUNvbXBvbmVudCgpOwogICAgICAgIH0KCiAgICAgICAgcHJpdmF0ZSB2b2lkIEZvcm0xX0xvYWQob2JqZWN0IHNlbmRlciwgRXZlbnRBcmdzIGUpCiAgICAgICAgewogICAgICAgICAgICBUcmVlVmlld01vdXNlT3ZlciB0diA9IG5ldyBUcmVlVmlld01vdXNlT3ZlcigpOwogICAgICAgICAgICB0di5Eb2NrID0gRG9ja1N0eWxlLkZpbGw7CiAgICAgICAgICAgIHR2LkRyYXdNb2RlID0gVHJlZVZpZXdEcmF3TW9kZS5Pd25lckRyYXdUZXh0OwogICAgICAgICAgICBmb3IgKGludCBpID0gMDsgaSA8IDEwMDsgaSsrKQogICAgICAgICAgICB7CiAgICAgICAgICAgICAgICB0di5Ob2Rlcy5BZGQoIm5vZGUiICsgaS5Ub1N0cmluZygpKTsKICAgICAgICAgICAgfQogICAgICAgICAgICB0aGlzLkNvbnRyb2xzLkFkZCh0dik7CiAgICAgICAgfQogICAgfQp9Cg==