private void viewMenuItem_DropDown_Closing(object sender, ToolStripDropDownClosingEventArgs e) { if (e.CloseReason != ToolStripDropDownCloseReason.ItemClicked) { return; } ToolStripDropDownMenu menu = sender as ToolStripDropDownMenu; ToolStripItem viewItem = menu != null?menu.GetItemAt(menu.PointToClient(Cursor.Position)) : null; if (viewItem == null) { return; } IMenuModelItem modelItem = this.GetModelItem(viewItem); if (modelItem == null) { return; } if (modelItem.Checkable) { e.Cancel = true; } }
private object findControl(int x, int y) { //Point newPoint = this.PointToScreen(new Point(x, y)); //POINT windowPoint = POINT.FromPoint(newPoint); POINT windowPoint = new POINT(x, y); IntPtr found = NativeUtils.WindowFromPoint(windowPoint); // we have a valid window handle if (found != IntPtr.Zero) { // give it another try, it might be a child window (disabled, hidden .. something else) // offset the point to be a client point of the active window if (NativeUtils.ScreenToClient(found, ref windowPoint)) { // check if there is some hidden/disabled child window at this point IntPtr childWindow = NativeUtils.ChildWindowFromPoint(found, windowPoint); if (childWindow != IntPtr.Zero) { // great, we have the inner child found = childWindow; } } object c = Control.FromHandle(found); /*if (c is MenuStrip)//MenuStrip继承自ToolStrip * { * MenuStrip m = c as MenuStrip; * c = m.GetItemAt(windowPoint.ToPoint()); * } * else*/if (c is ToolStripDropDownMenu) { ToolStripDropDownMenu m = c as ToolStripDropDownMenu; c = m.GetItemAt(windowPoint.ToPoint()); } else if (c is ToolStrip) { ToolStrip m = c as ToolStrip; c = m.GetItemAt(windowPoint.ToPoint()); } return(c); } else { return(null); } }