Capturing mouse events on a TreeNode
-
I've extended the TreeNode control to add an additional property. Now, what I'd like to do is capture the MouseDown event so I can perform some tasks when either the left or right mouse button is clicked. However, I can see that the TreeNode doesn't have any events to override. I tried capturing it with the TreeView control, but can't get the underlying object that was clicked. Any ideas? I was thinking about creating my own custom event in my extended control (TreeNodeExID)... but I can't find any examples or documentation... -AC Andrew Connell IM on MSN andrew@aconnell.com
-
I've extended the TreeNode control to add an additional property. Now, what I'd like to do is capture the MouseDown event so I can perform some tasks when either the left or right mouse button is clicked. However, I can see that the TreeNode doesn't have any events to override. I tried capturing it with the TreeView control, but can't get the underlying object that was clicked. Any ideas? I was thinking about creating my own custom event in my extended control (TreeNodeExID)... but I can't find any examples or documentation... -AC Andrew Connell IM on MSN andrew@aconnell.com
Override the WndProc procedure and handle the Windows Message WM_LBUTTONDOWN:
class TreeNodeExID : TreeNode
{
...
public const int WM_LBUTTONDOWN = 0x0201;
protected override void WndProc(ref Message m)
{
if(m.Msg == WM_LBUTTONDOWN)
{
//DO WORK HERE
}
base.WndProc(ref m);
}
}