private ButtonSelectedState GetButtonState(ToolStrip toolStrip, ToolStripItem item) { if (!item.Enabled) { return(ButtonSelectedState.Disabled); } if (item is ToolStripButton) { ToolStripButton button = (ToolStripButton)item; if (button.Checked) { return(ButtonSelectedState.Checked); } } if (item.Pressed) { return(ButtonSelectedState.Pressed); } else { Point cursorPos = toolStrip.PointToClient(Cursor.Position); if ((item.Visible) && (item.Bounds.Contains(cursorPos))) { return(ButtonSelectedState.Focused); } else { return(ButtonSelectedState.None); } } }
private void RenderToolButtonBackground(Graphics g, ToolStripButton button, ToolStrip toolstrip) { // We only draw a background if the item is selected or being pressed if (button.Enabled) { if (button.Checked) { if (button.Pressed) { DrawGradientToolItem(g, button, _itemToolItemPressedColors); } else if (button.Selected) { DrawGradientToolItem(g, button, _itemToolItemCheckPressColors); } else { DrawGradientToolItem(g, button, _itemToolItemCheckedColors); } } else { if (button.Pressed) { DrawGradientToolItem(g, button, _itemToolItemPressedColors); } else if (button.Selected) { DrawGradientToolItem(g, button, _itemToolItemSelectedColors); } } } else { if (button.Selected) { // Get the mouse position in tool strip coordinates Point mousePos = toolstrip.PointToClient(Control.MousePosition); // If the mouse is not in the item area, then draw disabled if (!button.Bounds.Contains(mousePos)) { DrawGradientToolItem(g, button, _itemDisabledColors); } } } }
private FindControlResult FindControl(ToolStrip ts, int x, int y) { var p = ts.PointToClient(new Point(x, y)); var item = GetAllChildren(ts).FirstOrDefault(c => c.Bounds.Contains(p)); if (item == null) { var res = new FindControlResult(ts.Parent.RectangleToScreen(ts.Bounds), ts.Name); return(res); } else { var res = new FindControlResult(ts.RectangleToScreen(item.Bounds), item.Name); return(res); } }
void cMS_MatchedGestures_MouseHover(object sender, EventArgs e) { foreach (IntPtr hwnd in m_hwndCmsList) { Win32.ShowWindow(hwnd, 0); } ToolStripMenuItem menuItem = (ToolStripMenuItem)sender; if (menuItem.DropDownItems.Count > 0) { ToolStrip parent = menuItem.GetCurrentParent(); Point position = parent.PointToClient(Cursor.Position); position.Y -= 2; //Debug.WriteLine(string.Format("cMS_MatchedGestures_MouseHover X: {0} Y: {1}", position.X, position.Y)); int y = position.Y - (position.Y % menuItem.Height); y = y == 0 ? 0 : y + 2; int x = menuItem.Width; Point newPos = parent.PointToScreen(new Point(x, y)); IntPtr handle = menuItem.DropDown.Handle; Win32.SetWindowPos(handle, Win32.HWND_TOPMOST, newPos.X, newPos.Y, 0, 0, Win32.SWP_SHOWWINDOW | Win32.SWP_NOACTIVATE | Win32.SWP_NOREDRAW); } }
public static ToolStripItem GetItemAtDeep(this ToolStrip toolstrip, Point screenPos) { if (!toolstrip.Visible) { return(null); } Point toolStripLocalPos = toolstrip.PointToClient(screenPos); ToolStripItem item = toolstrip.GetItemAt(toolStripLocalPos); if (item != null) { return(item); } ToolStripDropDownItem dropItem = toolstrip.GetActiveDropDown(); if (dropItem != null) { return(dropItem.DropDown.GetItemAtDeep(screenPos)); } return(null); }
public static ToolStripItem GetItemAtDeep(this ToolStrip t, Point screenPos) { if (!t.Visible) { return(null); } Point toolStripLocalPos = t.PointToClient(screenPos); ToolStripItem item = t.GetItemAt(toolStripLocalPos); if (item != null) { return(item); } ToolStripDropDownItem dropItem = t.Items.OfType <ToolStripDropDownItem>().FirstOrDefault(i => i.DropDown.Visible); if (dropItem != null) { return(dropItem.DropDown.GetItemAtDeep(screenPos)); } return(null); }