/// <summary> /// Vytvoří systémovou nabídku <see cref="System.Windows.Forms.ToolStripDropDownMenu"/> z dodaných funkcí. /// Do property <see cref="System.Windows.Forms.ToolStripItem.Tag"/> každé položky menu /// uloží referenci na prvek <see cref="FunctionItem"/>, z něhož je položka menu vytvořena. /// </summary> /// <param name="functionItems">Položky menu</param> /// <param name="modifyMenu">Akce, která může modifikovat menu ještě před přidáním položek</param> /// <returns></returns> public static System.Windows.Forms.ToolStripDropDownMenu CreateDropDownMenuFrom(IEnumerable <FunctionItem> functionItems, Action <System.Windows.Forms.ToolStripDropDownMenu> modifyMenu = null) { System.Windows.Forms.ToolStripDropDownMenu menu = Painter.CreateDropDownMenu(); if (modifyMenu != null) { modifyMenu(menu); } var items = CreateWinFormItems(functionItems); if (items != null) { menu.Items.AddRange(items); } return(menu); }
private async void createGlobalSOFiSTiKMenu() { await Task.Run(() => startTimer()); var editor = Grasshopper.Instances.DocumentEditor; foreach (var control in editor.Controls) { if (control is System.Windows.Forms.MenuStrip) { var gh_strip = control as System.Windows.Forms.MenuStrip; if (gh_strip.Name == "MainMenu") { var sofiItem = new System.Windows.Forms.ToolStripMenuItem("SOFiSTiK"); var dropDown = new System.Windows.Forms.ToolStripDropDownMenu(); var menuItems = new List <System.Windows.Forms.ToolStripMenuItem>(); menuItems.Add(GH_DocumentObject.Menu_AppendItem(dropDown, "Help", OnHelpClick)); menuItems.Add(GH_DocumentObject.Menu_AppendItem(dropDown, "About...", OnAboutClick)); var maxWidth = 0; foreach (var item in menuItems) { if (item.Width > maxWidth) { maxWidth = item.Width; } item.AutoSize = false; item.Height = 26; } foreach (var item in menuItems) { item.Width = maxWidth; } sofiItem.DropDown = dropDown; //gh_strip.Items.Insert(5, sofiItem); gh_strip.Items.Add(sofiItem); } } } }
public override GH_ObjectResponse RespondToMouseDown(GH_Canvas sender, GH_CanvasMouseEvent e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { GH_ValueListItem item2 = this.Owner.FirstSelectedItem; if (item2 != null) { if (item2.BoxRight.Contains(e.CanvasLocation)) { System.Windows.Forms.ToolStripDropDownMenu menu = new System.Windows.Forms.ToolStripDropDownMenu(); GH_ValueListItem activeItem = this.Owner.FirstSelectedItem; try { System.Collections.Generic.List <GH_ValueListItem> .Enumerator enumerator = this.Owner.ListItems.GetEnumerator(); while (enumerator.MoveNext()) { GH_ValueListItem existingItem = enumerator.Current; System.Windows.Forms.ToolStripMenuItem menuItem = new System.Windows.Forms.ToolStripMenuItem(existingItem.Name); menuItem.Click += new System.EventHandler(this.ValueMenuItem_Click); if (existingItem == activeItem) { menuItem.Checked = true; } menuItem.Tag = existingItem; menu.Items.Add(menuItem); } } finally { System.Collections.Generic.List <GH_ValueListItem> .Enumerator enumerator = new List <GH_ValueListItem> .Enumerator(); ((System.IDisposable)enumerator).Dispose(); } menu.Show(sender, e.ControlLocation); return(GH_ObjectResponse.Handled); } } } return(base.RespondToMouseDown(sender, e)); }