110,533
社区成员
发帖
与我相关
我的任务
分享
public partial class DoubleClickCatch : Form
{
private const int GWL_WNDPROC = -4;
private const int WM_LBUTTONDBLCLK = 0x0203;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, MyWndProc wndProc);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public delegate IntPtr MyWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private IntPtr ldWndProc = IntPtr.Zero;
private IntPtr OldWndProc;
private MyWndProc Wpr = null;
public DoubleClickCatch()
{
InitializeComponent();
InitializeThatControl();
}
private void InitializeThatControl()
{
this.Wpr = new MyWndProc(this.MyControlWndProc);
this.OldWndProc = SetWindowLong(treeView1.Handle, GWL_WNDPROC, Wpr);
}
private IntPtr MyControlWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
{
switch (msg)
{
case WM_LBUTTONDBLCLK:
label1.Text = "double click";
return (IntPtr)0;
default:
return CallWindowProc(OldWndProc, hWnd, msg, wParam, lParam);
}
}
private void ChangeChild(TreeNode node, bool state)
{
node.Checked = state;
foreach (TreeNode tn in node.Nodes)
ChangeChild(tn, state);
}
private void ChangeParent(TreeNode node)
{
if (node.Parent != null)
{
int brotherNodeCheckedCount = 0;
foreach (TreeNode tn in node.Parent.Nodes)
{
if (tn.Checked == true)
brotherNodeCheckedCount++;
}
if (brotherNodeCheckedCount == 0)
{
node.Parent.Checked = false;
ChangeParent(node.Parent);
}
if (brotherNodeCheckedCount >= 1)
{
node.Parent.Checked = true;
ChangeParent(node.Parent);
}
}
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Parent != null)
{
ChangeParent(e.Node);
}
if (e.Node.GetNodeCount(false) > 0)
{
ChangeChild(e.Node, e.Node.Checked);
}
}
}
[/quote]
老哥啊,这个系统本身就没有把他判断成双击啊,实际操作是双击,但是系统把他判断成两次单击
http://www.cnblogs.com/sqshine/archive/2008/12/29/1364236.html
我这边在aftercheck的时候执行了这个,你可以尝试一下,然后去双击节点的复选框,监视一下你双击的这个节点的checked属性,就知道问题了。
public partial class DoubleClickCatch : Form
{
private const int GWL_WNDPROC = -4;
private const int WM_LBUTTONDBLCLK = 0x0203;
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr SetWindowLong(IntPtr hWnd, int nIndex, MyWndProc wndProc);
[DllImport("user32.dll", CharSet = CharSet.Auto)]
private static extern IntPtr CallWindowProc(IntPtr wndProc, IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
public delegate IntPtr MyWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam);
private IntPtr ldWndProc = IntPtr.Zero;
private IntPtr OldWndProc;
private MyWndProc Wpr = null;
public DoubleClickCatch()
{
InitializeComponent();
InitializeThatControl();
}
private void InitializeThatControl()
{
this.Wpr = new MyWndProc(this.MyControlWndProc);
this.OldWndProc = SetWindowLong(treeView1.Handle, GWL_WNDPROC, Wpr);
}
private IntPtr MyControlWndProc(IntPtr hWnd, int msg, IntPtr wParam, IntPtr lParam)
{
switch (msg)
{
case WM_LBUTTONDBLCLK:
label1.Text = "double click";
return (IntPtr)0;
default:
return CallWindowProc(OldWndProc, hWnd, msg, wParam, lParam);
}
}
private void ChangeChild(TreeNode node, bool state)
{
node.Checked = state;
foreach (TreeNode tn in node.Nodes)
ChangeChild(tn, state);
}
private void ChangeParent(TreeNode node)
{
if (node.Parent != null)
{
int brotherNodeCheckedCount = 0;
foreach (TreeNode tn in node.Parent.Nodes)
{
if (tn.Checked == true)
brotherNodeCheckedCount++;
}
if (brotherNodeCheckedCount == 0)
{
node.Parent.Checked = false;
ChangeParent(node.Parent);
}
if (brotherNodeCheckedCount >= 1)
{
node.Parent.Checked = true;
ChangeParent(node.Parent);
}
}
}
private void treeView1_NodeMouseClick(object sender, TreeNodeMouseClickEventArgs e)
{
if (e.Node.Parent != null)
{
ChangeParent(e.Node);
}
if (e.Node.GetNodeCount(false) > 0)
{
ChangeChild(e.Node, e.Node.Checked);
}
}
}