// playyuer@Microshaoft.com invent
//一个 TreeView 的派生类: TreeViewEx 实现 NodeShowToolTip、NodeDoubleClick 事件
//1.实现了 NodeShowToolTip 事件,结合键盘 Ctrl 键显示及设置 ToolTipText
//2.实现了 NodeDoubleClick 事件,可在调用中只响应"叶子"节点
//3.点击 TreeView 空白处不选中任何节点
//Class1.cs
using System;
public class TreeViewEx : System.Windows.Forms.TreeView
{
public event TreeViewExEventHandler NodeDoubleClick;
public event TreeViewExEventHandler NodeShowToolTip;
private void OnNodeDoubleClick(System.Windows.Forms.TreeNode xx)
{
if(this.NodeDoubleClick != null)
{
this.NodeDoubleClick(this,new TreeViewExEventArgs(xx));
}
}
private void OnNodeShowToolTip(System.Windows.Forms.TreeNode xx, System.Windows.Forms.ToolTip yy)
{
if(this.NodeShowToolTip != null)
{
if ((xx != null) && (this.toolTip !=null))
this.NodeShowToolTip(this,new TreeViewExEventArgs(xx,this.toolTip));
}
}
protected override void OnDoubleClick(System.EventArgs e)
{
if (this.SelectedNode != null)
this.OnNodeDoubleClick(this.SelectedNode);
base.OnDoubleClick(e);
}
private System.Windows.Forms.ToolTip toolTip;
public TreeViewEx()
{
toolTip = new System.Windows.Forms.ToolTip();
this.toolTip.InitialDelay = 300;
this.toolTip.ReshowDelay = 0;
}
protected override void OnClick (System.EventArgs e)
{
if (this.GetNodeAt(System.Windows.Forms.TreeView.MousePosition.X,System.Windows.Forms.TreeView.MousePosition.Y) == null)
this.SelectedNode = null;
base.OnClick(e);
}
protected override void OnMouseDown (System.Windows.Forms.MouseEventArgs e)
{
if (this.GetNodeAt(e.X,e.Y) == null)
this.SelectedNode = null;
base.OnMouseDown(e);
}
private System.Windows.Forms.TreeNode LastTreeNode;
protected override void OnMouseMove (System.Windows.Forms.MouseEventArgs e)
{
this.Cursor = System.Windows.Forms.Cursors.Default ;
System.Windows.Forms.TreeNode treeNode;
treeNode = this.GetNodeAt(e.X,e.Y) ;
&nbs