internal void HandleToolStripMouseLeave(ToolStrip toolStrip) { if (InTransition && toolStrip == fromItem.ParentInternal) { // restore the selection back to CurrentItem. // we're about to fall off the edge of the toolstrip, something should be selected // at all times while we're InTransition mode - otherwise it looks really funny // to have an auto expanded item if (CurrentItem is not null) { CurrentItem.Select(); } } else { // because we've split up selected/pressed, we need to make sure // that onmouseleave we make sure there's a selected menu item. if (toolStrip.IsDropDown && toolStrip.ActiveDropDowns.Count > 0) { ToolStripMenuItem menuItem = (!(toolStrip.ActiveDropDowns[0] is ToolStripDropDown dropDown)) ? null : dropDown.OwnerItem as ToolStripMenuItem; if (menuItem is not null && menuItem.Pressed) { menuItem.Select(); } } } }
internal void HandleToolStripMouseLeave(ToolStrip toolStrip) { if (this.InTransition && (toolStrip == this.fromItem.ParentInternal)) { if (this.CurrentItem != null) { this.CurrentItem.Select(); } } else if (toolStrip.IsDropDown && (toolStrip.ActiveDropDowns.Count > 0)) { ToolStripDropDown down = toolStrip.ActiveDropDowns[0] as ToolStripDropDown; ToolStripMenuItem item = (down == null) ? null : (down.OwnerItem as ToolStripMenuItem); if ((item != null) && item.Pressed) { item.Select(); } } }
private void Init() { //File menu var FileOpen = new ToolStripMenuItem("&Open"); FileOpen.Click += FileOpenAction; var FileClose = new ToolStripMenuItem("&Close"); FileClose.Click += FileCloseAction; var FileExit = new ToolStripMenuItem("E&xit"); FileExit.Click += FileExitAction; var file = new ToolStripMenuItem("&File"); file.DropDownItems.AddRange(new ToolStripMenuItem[] {FileOpen,FileClose,FileExit }); //Help Menu var HelpAbout = new ToolStripMenuItem("&About"); HelpAbout.Click += HelpAboutAction; var help = new ToolStripMenuItem("&Help"); help.DropDownItems.Add(HelpAbout); //Seperator var seperator = new ToolStripSeparator(); //Spinner SpinnerUi = new NumericUpDown(); SpinnerUi.Minimum = 1; SpinnerUi.Maximum = decimal.MaxValue; SpinnerUi.MaximumSize = new System.Drawing.Size(60,int.MaxValue); SpinnerUi.InterceptArrowKeys = false; //we're doing our own key capture SpinnerUi.KeyDown += OnSpinnerKeyDown; //keydown repeats if key is being held SpinnerUi.ValueChanged += OnSpinnerChange; var spinnerHost = new ToolStripControlHost(SpinnerUi,"Width"); //Multiplier MultiplierUi = new ToolStripDropDownButton(); MultiplierUi.DropDownItemClicked += OnMultiplierChanged; ToolStripMenuItem first; MultiplierUi.DropDownItems.AddRange( new ToolStripItem[] { first = new ToolStripMenuItem("&1x") ,new ToolStripMenuItem("&2x") ,new ToolStripMenuItem("&4x") ,new ToolStripMenuItem("&8x") }); first.Select(); OnMultiplierChanged(null,new ToolStripItemClickedEventArgs(first)); //Add everything to the menu Menu = new MenuStrip(); Menu.Items.AddRange(new ToolStripItem[] { file,help,seperator,MultiplierUi,spinnerHost }); Menu.Dock = DockStyle.Top; }
/// <summary> /// builds the ContextMenuStrip with the clipboard value history and the Control Items /// </summary> public void BuildContextMenuStrip() { try { this.notifyIconMenu.Items.Clear(); ToolStripMenuItem currentItem = null; List<IType> items = this.GetLastElements(this.settings.MenuItemAmount); string latestItemKey = ""; if (items.Count > 0) { latestItemKey = items.Last().Key; } if (this.settings.OrderDesc) { items.Reverse(); } foreach (IType item in items) { currentItem = new ToolStripMenuItem( item.MenuValue, null, new EventHandler(Paste_Click), item.Key ); this.notifyIconMenu.Items.Add(currentItem); if (latestItemKey == item.Key) { currentItem.Select(); } } this.AddControlMenuItems(); } catch (Exception e) { MessageBox.Show(e.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error); } }
protected virtual void OnMenuItemsLoad(EventArgs e) { menu.RightToLeft = this.RightToLeft; menu.Items.Clear(); List<ToolStripMenuItem> list = new List<ToolStripMenuItem>(); int nr = Items.Count; for (int i = 0; i < nr; i++) { TabControlItem item = this.Items[i]; if (!item.Visible) continue; ToolStripMenuItem tItem = new ToolStripMenuItem(item.Title); tItem.Tag = item; if (item.Selected) tItem.Select(); list.Add(tItem); } list.Sort(CompareSortText); menu.Items.AddRange(list.ToArray()); OnMenuItemsLoaded(EventArgs.Empty); }
private void OnMenuItemsLoad(EventArgs e) { this.Menu.RightToLeft = this.RightToLeft; this.Menu.Items.Clear(); List<ToolStripMenuItem> list = new List<ToolStripMenuItem>(); for (int i = 0; i < this.Items.Count; i++) { TabControlItem item = this.Items[i]; if (!item.Visible) continue; ToolStripMenuItem tItem = new ToolStripMenuItem(item.Title); tItem.Tag = item; if (item.Selected) tItem.Select(); list.Add(tItem); } // Sort by caption, else do nothing i.e. sorted by call sequence not by caption!!!!! if (Terminals.Configuration.Files.Main.Settings.Settings.SortTabPagesByCaption) list.Sort(CompareSortText); this.Menu.Items.AddRange(list.ToArray()); this.OnMenuItemsLoaded(EventArgs.Empty); }