private bool WmRButtonDown(ref Message m) { if (!ContainsFocus) { Focus(); } Native.TV_HITTESTINFO tvhip = new Native.TV_HITTESTINFO(); tvhip.pt_x = (int)(short)m.LParam; tvhip.pt_y = ((int)m.LParam >> 16); IntPtr handlenode = Native.SendMessage(this.Handle, Native.TVM_HITTEST, 0, tvhip); OnMouseDown(new MouseEventArgs(MouseButtons.Right, 1, (int)(short)m.LParam, (int)m.LParam >> 16, 0)); if ((tvhip.flags & Native.TVHT_ONITEM) != 0) { TreeNode node = TreeNode.FromHandle(this, tvhip.hItem); if (this.allowEmptySelection && !IsSelectedState(node)) { ExtendSelection(node, false, false, TreeViewAction.ByMouse); } } // show context menu Native.SendMessage(Handle, (int)Native.Msg.WM_CONTEXTMENU, (int)Handle, (IntPtr)Native.GetMessagePos()); m.Result = (IntPtr)1; return(true); }
private bool WmLButtonDown(ref Message m) { if (!ContainsFocus) { Focus(); } Native.TV_HITTESTINFO tvhip = new Native.TV_HITTESTINFO(); tvhip.pt_x = (int)(short)m.LParam; tvhip.pt_y = ((int)m.LParam >> 16); IntPtr handlenode = Native.SendMessage(this.Handle, Native.TVM_HITTEST, 0, tvhip); int keys = (int)m.WParam; if ((tvhip.flags & Native.TVHT_ONITEM) != 0) { TreeNode node = null; if (handlenode == IntPtr.Zero) { Debug.Assert(false); return(false); } node = TreeNode.FromHandle(this, handlenode); OnMouseDown(new MouseEventArgs(MouseButtons.Left, 1, (int)(short)m.LParam, (int)m.LParam >> 16, 0)); ExtendSelection(node, (keys & Native.MK_SHIFT) != 0, (keys & Native.MK_CONTROL) != 0, TreeViewAction.ByMouse); } else if ((tvhip.flags & Native.TVHT_ONITEMBUTTON) != 0) { // collapse/expand // use default handler return(false); } else { if (this.allowEmptySelection) { ExtendSelection(null as TreeNode, (keys & Native.MK_SHIFT) != 0, (keys & Native.MK_CONTROL) != 0, TreeViewAction.ByMouse); } return(false); } return(true); }