private void PerformClick() { SWF.ToolStripItem item = (SWF.ToolStripItem)Provider.Component; if (item.Owner != null && item.Owner.InvokeRequired) { item.Owner.BeginInvoke(new SWF.MethodInvoker(PerformClick)); return; } var currentParent = item.OwnerItem as SWF.ToolStripMenuItem; // Invoking without a visible parent results in exceptions if (currentParent != null && !currentParent.DropDown.Visible) { return; } var dropdown = item as SWF.ToolStripDropDownItem; bool hide = false; if (dropdown != null) { hide = dropdown.Pressed; } // Make sure selection changes, or else another item's // dropdown menu might still appear. if (item.Owner != null) { item.Select(); } item.PerformClick(); // PerformClick does _not_ show/hide the DropDown, so // we must do this manually. On Vista, clicking the // button appears to both Show the drop down and // Perform a click, so we emulate that behavior. if (dropdown != null && !(item is SWF.ToolStripSplitButton)) { if (hide) { dropdown.HideDropDown(); } else { dropdown.ShowDropDown(); } } }
internal virtual void ChangeSelection(ToolStripItem nextItem) { if (nextItem != null) { ToolStripControlHost host = nextItem as ToolStripControlHost; if (base.ContainsFocus && !this.Focused) { this.FocusInternal(); if (host == null) { this.KeyboardActive = true; } } if (host != null) { if (this.hwndThatLostFocus == IntPtr.Zero) { this.SnapFocus(System.Windows.Forms.UnsafeNativeMethods.GetFocus()); } host.Control.Select(); host.Control.FocusInternal(); } nextItem.Select(); ToolStripMenuItem item = nextItem as ToolStripMenuItem; if ((item != null) && !this.IsDropDown) { item.HandleAutoExpansion(); } } }
internal virtual void ProcessDuplicateMnemonic(ToolStripItem item, char charCode) { if (this.CanProcessMnemonic() && (item != null)) { this.SetFocusUnsafe(); item.Select(); } }
internal void ChangeSelection (ToolStripItem nextItem) { if (Application.KeyboardCapture != this) ToolStripManager.SetActiveToolStrip (this, ToolStripManager.ActivatedByKeyboard); foreach (ToolStripItem tsi in this.Items) if (tsi != nextItem) tsi.Dismiss (ToolStripDropDownCloseReason.Keyboard); ToolStripItem current = GetCurrentlySelectedItem (); if (current != null && !(current is ToolStripControlHost)) this.FocusInternal (true); if (nextItem is ToolStripControlHost) (nextItem as ToolStripControlHost).Focus (); nextItem.Select (); if (nextItem.Parent is MenuStrip && (nextItem.Parent as MenuStrip).MenuDroppedDown) (nextItem as ToolStripMenuItem).HandleAutoExpansion (); }
/// <summary> /// Assign ExpressionMemberContainer to each of Context Menu Strip's items that are child to specified item. /// Item with value equal to current also gets selected. /// Called from AssignContainerToContextMenuStrip and recursively calls itself. /// </summary> /// <param name="item">Current item.</param> /// <param name="container">Container to be asigned.</param> /// <param name="currentValue">Item with this value will be selected.</param> private static void AssignContainerToContextMenuStrip_RecursivelyAssign(ToolStripItem item, ExpressionMemberContainer container, string currentValue) { if (!(item is ToolStripMenuItem)) return; bool itemSelected = false; foreach (ToolStripItem innerItem in ((ToolStripMenuItem)item).DropDownItems) { AssignContainerToContextMenuStrip_RecursivelyAssign(innerItem, container, currentValue); itemSelected = itemSelected || item.Selected; } item.Tag = container; if (container.Member.ValueDescription.AreEqual(container.Member.ValueToXml(item.Text), currentValue)) item.Select(); }