public static void ShowIconMenu <T>(Point position, IEnumerable <Tuple <T, Bitmap> > items, Action <T> pickHandler) { List <Tuple <T, Bitmap> > itemList = items?.OrderBy(item => item.Item1.ToString()).ToList(); if (itemList == null || !itemList.Any()) { return; } ContextMenuStrip contextMenu = new ContextMenuStrip(); ToolStripDropDownClosedEventHandler contextMenuClosedEventHandler = null; ToolStripItemClickedEventHandler menuItemClickedEventHandler = null; contextMenuClosedEventHandler = (sender, e) => { contextMenu.Closed -= contextMenuClosedEventHandler; contextMenu.ItemClicked -= menuItemClickedEventHandler; }; menuItemClickedEventHandler = (sender, e) => { contextMenu.Closed -= contextMenuClosedEventHandler; contextMenu.ItemClicked -= menuItemClickedEventHandler; contextMenu.Close(); pickHandler((T)e.ClickedItem.Tag); }; contextMenu.Closed += contextMenuClosedEventHandler; contextMenu.ItemClicked += menuItemClickedEventHandler; itemList.ForEach(item => contextMenu.Items.Add(new ToolStripMenuItem(item.Item1.ToString()) { Tag = item.Item1, Image = item.Item2 })); contextMenu.Show(position); }
/// <summary> /// Extends BeginInvoke so that when a state object is not needed, null does not need to be passed. /// <example> /// toolstripitemclickedeventhandler.BeginInvoke(sender, e, callback); /// </example> /// </summary> public static IAsyncResult BeginInvoke(this ToolStripItemClickedEventHandler toolstripitemclickedeventhandler, Object sender, ToolStripItemClickedEventArgs e, AsyncCallback callback) { if (toolstripitemclickedeventhandler == null) { throw new ArgumentNullException("toolstripitemclickedeventhandler"); } return(toolstripitemclickedeventhandler.BeginInvoke(sender, e, callback, null)); }
protected internal virtual void OnDropDownItemClicked(ToolStripItemClickedEventArgs e) { ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [DropDownItemClickedEvent]); if (eh != null) { eh(this, e); } }
protected internal virtual void OnDropDownItemClicked(ToolStripItemClickedEventArgs e) { if (this.DropDown.OwnerItem == this) { ToolStripItemClickedEventHandler handler = (ToolStripItemClickedEventHandler)base.Events[EventDropDownItemClicked]; if (handler != null) { handler(this, e); } } }
protected virtual void OnItemClicked(ToolStripItemClickedEventArgs e) { //if (this.KeyboardActive) // ToolStripManager.SetActiveToolStrip (null, false); ToolStripItemClickedEventHandler eh = (ToolStripItemClickedEventHandler)(Events [ItemClickedEvent]); if (eh != null) { eh(this, e); } }
/// <include file='doc\ToolStripDropDownItem.uex' path='docs/doc[@for="ToolStripDropDownItem.OnDropDownItemClicked"]/*' /> /// <devdoc> /// called when the default item is clicked /// </devdoc> protected internal virtual void OnDropDownItemClicked(ToolStripItemClickedEventArgs e) { // only send the event if we're the thing that currently owns the DropDown. if (DropDown.OwnerItem == this) { ToolStripItemClickedEventHandler handler = (ToolStripItemClickedEventHandler)Events[EventDropDownItemClicked]; if (handler != null) { handler(this, e); } } }
public static void ShowMenu <T1, T2>(Point position, IEnumerable <T1> rootItems, IEnumerable <T2> items, Action <T1, T2> pickHandler) { IEnumerable <T1> rootItemList = rootItems as IList <T1> ?? rootItems?.ToList(); if (rootItemList == null || !rootItemList.Any()) { return; } List <T2> itemList = items?.OrderBy(item => item.ToString()).ToList(); if (itemList == null || !itemList.Any()) { return; } ContextMenuStrip contextMenu = new ContextMenuStrip(); foreach (T1 rootItem in rootItemList) { ToolStripMenuItem rootMenuItem = new ToolStripMenuItem(rootItem.ToString()) { Tag = rootItem }; contextMenu.Items.Add(rootMenuItem); itemList.ForEach(item => rootMenuItem.DropDownItems.Add(new ToolStripMenuItem(item.ToString()) { Tag = new Tuple <T1, T2>(rootItem, item) })); } ToolStripDropDownClosedEventHandler contextMenuClosedEventHandler = null; ToolStripItemClickedEventHandler menuItemClickedEventHandler = null; contextMenuClosedEventHandler = (sender, e) => { contextMenu.Closed -= contextMenuClosedEventHandler; contextMenu.Items.Cast <ToolStripMenuItem>().ToList().ForEach(x => x.DropDownItemClicked -= menuItemClickedEventHandler); }; menuItemClickedEventHandler = (sender, e) => { contextMenu.Closed -= contextMenuClosedEventHandler; contextMenu.Items.Cast <ToolStripMenuItem>().ToList().ForEach(x => x.DropDownItemClicked -= menuItemClickedEventHandler); contextMenu.Close(); Tuple <T1, T2> tag = (Tuple <T1, T2>)e.ClickedItem.Tag; pickHandler(tag.Item1, tag.Item2); }; contextMenu.Closed += contextMenuClosedEventHandler; contextMenu.Items.Cast <ToolStripMenuItem>().ToList().ForEach(x => x.DropDownItemClicked += menuItemClickedEventHandler); contextMenu.Show(position); }
public static void CreateHierarchicalContextMenuItemsFromTypes(ToolStripMenuItem parentMenuItem, IEnumerable<Type> types, Func<Type, Image> getNodeImageFunc, ToolStripItemClickedEventHandler clickEventHandler, IEditorCategoryProvider editorCategoryProvider, Func<Type, string> getNameFunc = null) { ResetMenuToOriginalState(parentMenuItem); List<ToolStripItem> newItems = new List<ToolStripItem>(); foreach (Type type in types) { // Generate category item string[] category = editorCategoryProvider.GetCategory(type); ToolStripMenuItem categoryItem = parentMenuItem; for (int i = 0; i < category.Length; i++) { ToolStripMenuItem subCatItem; if (categoryItem == parentMenuItem) subCatItem = newItems.FirstOrDefault(item => item.Name == category[i]) as ToolStripMenuItem; else subCatItem = categoryItem.DropDownItems.Find(category[i], false).FirstOrDefault() as ToolStripMenuItem; if (subCatItem == null) { subCatItem = new ToolStripMenuItem(category[i]) { Name = category[i], Tag = type.Assembly }; subCatItem.DropDownItemClicked += clickEventHandler; if (categoryItem == parentMenuItem) InsertToolStripTypeItem(newItems, subCatItem); else InsertToolStripTypeItem(categoryItem.DropDownItems, subCatItem); } categoryItem = subCatItem; } var image = getNodeImageFunc != null ? getNodeImageFunc(type) : null; ToolStripMenuItem typeItem = new ToolStripMenuItem(getNameFunc != null ? getNameFunc(type) : type.Name, image); typeItem.Tag = type; if (categoryItem == parentMenuItem) InsertToolStripTypeItem(newItems, typeItem); else InsertToolStripTypeItem(categoryItem.DropDownItems, typeItem); } parentMenuItem.DropDownItems.AddRange(newItems.ToArray()); }
/// <summary> /// Create a dropdown toolbar button. /// </summary> /// <param name="itemName">The button name.</param> /// <param name="onClick">The button's click event handler.</param> /// <returns>The button.</returns> public static ToolStripDropDownButton CreateToolbarDropDownButton( string itemName, ToolStripItemClickedEventHandler onClick) { ToolStripDropDownButton button = new ToolStripDropDownButton(); button.Name = itemName; if (onClick != null) { button.DropDownItemClicked += onClick; } return(button); }
public static void ShowMultiSelectMenu <T>(Point position, IEnumerable <Tuple <T, bool> > items, Action <List <T> > pickHandler) { List <Tuple <T, bool> > itemList = items?.OrderBy(item => item.Item1.ToString()).ToList(); if (itemList == null || !itemList.Any()) { return; } bool anyItemClicked = false; ContextMenuStrip contextMenu = new ContextMenuStrip(); ToolStripDropDownClosedEventHandler contextMenuClosedEventHandler = null; ToolStripDropDownClosingEventHandler contextMenuClosingEventHandler = null; ToolStripItemClickedEventHandler menuItemClickedEventHandler = null; contextMenuClosedEventHandler = (sender, e) => { contextMenu.Closed -= contextMenuClosedEventHandler; contextMenu.Closing -= contextMenuClosingEventHandler; contextMenu.ItemClicked -= menuItemClickedEventHandler; }; contextMenuClosingEventHandler = (sender, e) => { if (e.CloseReason == ToolStripDropDownCloseReason.ItemClicked) { e.Cancel = true; ((ToolStripDropDownMenu)sender).Invalidate(); } else if (anyItemClicked) { List <T> selectedItems = ((ToolStripDropDownMenu)sender).Items.Cast <ToolStripMenuItem>().Where(x => x.Checked).Select(x => (T)x.Tag).ToList(); pickHandler(selectedItems); } }; menuItemClickedEventHandler = (sender, e) => { ToolStripMenuItem clickedItem = (ToolStripMenuItem)e.ClickedItem; clickedItem.Checked = !clickedItem.Checked; anyItemClicked = true; }; contextMenu.Closed += contextMenuClosedEventHandler; contextMenu.Closing += contextMenuClosingEventHandler; contextMenu.ItemClicked += menuItemClickedEventHandler; itemList.ForEach(item => contextMenu.Items.Add(new ToolStripMenuItem(item.Item1.ToString()) { Tag = item.Item1, Checked = item.Item2 })); contextMenu.Show(position); }
private void AssignMainFormFields(MainForm mainForm) { this.favoritesToolStripMenuItem = mainForm.favoritesToolStripMenuItem; this.tscConnectTo = mainForm.tscConnectTo; this.serverToolStripMenuItemClick = mainForm.ServerToolStripMenuItem_Click; this.favoriteToolBar = mainForm.favoriteToolBar; this.quickContextMenu = mainForm.QuickContextMenu; this.quickContextMenuItemClicked = mainForm.QuickContextMenu_ItemClicked; this.groupsToolStripMenuItem = mainForm.groupsToolStripMenuItem; this.groupsSeparator = mainForm.groupsSeparator; this.addTerminalToGroupToolStripMenuItem = mainForm.addTerminalToGroupToolStripMenuItem; this.saveTerminalsAsGroupToolStripMenuItem = mainForm.saveTerminalsAsGroupToolStripMenuItem; this.groupToolStripMenuItemClick = mainForm.GroupToolStripMenuItem_Click; this.groupAddToolStripMenuItemClick = mainForm.GroupAddToolStripMenuItem_Click; }
public static void MainContextConfigurator(NotifyIcon notifyIco, ToolStripItemClickedEventHandler eventHandler) { var strip = new ContextMenuStrip(); var titleLabel = new ToolStripLabel("StarSync"); titleLabel.Font = new Font("Segoe UI", 12, FontStyle.Regular); strip.Items.Add(titleLabel); strip.Items.Add(new ToolStripSeparator()); strip.Items.Add("Sync"); strip.Items.Add("History"); strip.Items.Add("Web Dashboard"); strip.Items.Add("Options"); strip.Items.Add("About"); strip.Items.Add("Logout"); strip.Items.Add(new ToolStripSeparator()); strip.Items.Add("Exit"); strip.ItemClicked += eventHandler; notifyIco.ContextMenuStrip = strip; }
public FavoritesMenuLoader(ToolStripMenuItem favoritesToolStripMenuItem, ToolStripComboBox tscConnectTo, EventHandler serverToolStripMenuItem_Click, ToolStrip favoriteToolBar, ContextMenuStrip quickContextMenu, ToolStripItemClickedEventHandler quickContextMenu_ItemClicked) { this.favoritesToolStripMenuItem = favoritesToolStripMenuItem; this.tscConnectTo = tscConnectTo; this.serverToolStripMenuItem_Click = serverToolStripMenuItem_Click; this.favoriteToolBar = favoriteToolBar; this.quickContextMenu = quickContextMenu; this.quickContextMenu_ItemClicked = quickContextMenu_ItemClicked; this.favoritesToolStripMenuItem.DropDownItems.Add("-"); this.CreateUntaggedItem(); this.CreateTrayMenuItems(); this.UpdateMenuAndContextMenu(); Settings.ConfigurationChanged += this.OnSettingsConfigurationChanged; DataDispatcher.Instance.TagsChanged += Instance_TagsChanged; }
/// <summary> /// Adds the required items in a context menu. /// </summary> /// <param name="contextMenu">The context menu in which to display items.</param> /// <param name="onClickEventHandler">Method to call when a menu item is clicked.</param> public abstract void CreateContextMenu(ContextMenuStrip contextMenu, ToolStripItemClickedEventHandler onClickEventHandler);
public static void CreateHierarchicalContextMenuItemsFromTypes(ToolStripMenuItem parentMenuItem, IEnumerable <Type> types, Func <Type, Image> getNodeImageFunc, ToolStripItemClickedEventHandler clickEventHandler, IEditorCategoryProvider editorCategoryProvider, Func <Type, string> getNameFunc = null) { ResetMenuToOriginalState(parentMenuItem); List <ToolStripItem> newItems = new List <ToolStripItem>(); foreach (Type type in types) { // Generate category item string[] category = editorCategoryProvider.GetCategory(type); ToolStripMenuItem categoryItem = parentMenuItem; for (int i = 0; i < category.Length; i++) { ToolStripMenuItem subCatItem; if (categoryItem == parentMenuItem) { subCatItem = newItems.FirstOrDefault(item => item.Name == category[i]) as ToolStripMenuItem; } else { subCatItem = categoryItem.DropDownItems.Find(category[i], false).FirstOrDefault() as ToolStripMenuItem; } if (subCatItem == null) { subCatItem = new ToolStripMenuItem(category[i]) { Name = category[i], Tag = type.Assembly }; subCatItem.DropDownItemClicked += clickEventHandler; if (categoryItem == parentMenuItem) { InsertToolStripTypeItem(newItems, subCatItem); } else { InsertToolStripTypeItem(categoryItem.DropDownItems, subCatItem); } } categoryItem = subCatItem; } var image = getNodeImageFunc != null?getNodeImageFunc(type) : null; ToolStripMenuItem typeItem = new ToolStripMenuItem(getNameFunc != null ? getNameFunc(type) : type.Name, image); typeItem.Tag = type; if (categoryItem == parentMenuItem) { InsertToolStripTypeItem(newItems, typeItem); } else { InsertToolStripTypeItem(categoryItem.DropDownItems, typeItem); } } parentMenuItem.DropDownItems.AddRange(newItems.ToArray()); }
// private void AddNodeEnumToPropertyGrid(string title, string value, object tag, ArrayList list, ToolStripItemClickedEventHandler handler, bool addEmtpy) //{ //} private void AddNodeEnumToPropertyGrid(string title, string value, object tag, TreeNode parent, ToolStripItemClickedEventHandler handler, bool addEmtpy) { int row = dataGridView.Rows.Add(title, (value != null && value.Length > 0 ? value : "<Right Click For Options>")); dataGridView.Rows[row].Tag = tag; DataGridViewCell dgc = dataGridView[1, row]; dgc.ReadOnly = true; if (dgc.ContextMenuStrip == null) dgc.ContextMenuStrip = new ContextMenuStrip(); dgc.ContextMenuStrip.Items.Clear(); dgc.ToolTipText = "Right Click For Options"; dgc.ContextMenuStrip.ItemClicked += handler; AddChildrenToEnum(parent, dgc.ContextMenuStrip, dataGridView.Rows[row]); if (addEmtpy) { ToolStripItem tsi = dgc.ContextMenuStrip.Items.Add("<No Selection>"); tsi.Tag = new ContextMenuItemData(dataGridView.Rows[row], null, "<No Selection>"); } }
internal List<ToolStripItem> CreateBranchMenu(bool fCurrent, IContainer container, ToolStripItemClickedEventHandler itemClickedEvent) { QTabItem item = fCurrent ? CurrentTab : ContextMenuedTab; List<ToolStripItem> list = new List<ToolStripItem>(); List<LogData> branches = item.Branches; if(branches.Count > 0) { ToolStripMenuItem item2 = new ToolStripMenuItem(QTUtility.ResMain[0x18]); item2.Tag = item; item2.DropDown = new DropDownMenuBase(container, true, true); item2.DropDown.ImageList = QTUtility.ImageListGlobal; item2.DropDownItemClicked += itemClickedEvent; int index = -1; foreach(LogData data in branches) { index++; if(IsSpecialFolderNeedsToTravel(data.Path)) { if(LogEntryDic.ContainsKey(data.Hash)) { goto Label_00B3; } continue; } if(!QTUtility2.PathExists(data.Path)) { continue; } Label_00B3: item2.DropDownItems.Add(MenuUtility.CreateMenuItem(new MenuItemArguments(data.Path, false, index, MenuGenre.Branch))); } if(item2.DropDownItems.Count > 0) { list.Add(new ToolStripSeparator()); list.Add(item2); } } return list; }
/// <summary> /// Required method for Designer support - do not modify /// the contents of this method with the code editor. /// </summary> private void InitializeComponent() { Checkers = this; this.components = new System.ComponentModel.Container(); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(Config.ClientSizeWidth, Config.ClientSizeHeight); this.Text = Config.AppName; this.DoubleBuffered = true; this.KeyPreview = true; //so that OnKeyPress works // //Application area // var panel = new TableLayoutPanel(); panel.RowCount = 2; panel.ColumnCount = 2; panel.Dock = DockStyle.Fill; // the board Board = new BoardUct(Config.BoardWidth, Config.BoardHeight); Board.OnSelected += Board_OnSelected; panel.Controls.Add(Board, 1, 0); // the previous moves section Moves = new MovesUct(Config.MovesHeight, Config.MovesWidth); panel.Controls.Add(Moves, 0, 0); Controls.Add(panel); // // Status Line area // var panelS = new TableLayoutPanel(); panelS.Height = Config.StatusHeight; panelS.RowCount = 1; panelS.ColumnCount = 2; panelS.ColumnStyles.Add(new ColumnStyle(SizeType.Absolute, (int)(Config.ClientSizeWidth * .4))); panelS.Dock = DockStyle.Bottom; // Left statusStrip StatusStripL = new StatusStrip(); StatusStripL.Items.Add(new ToolStripStatusLabel()); // Right statusStrip StatusStripR = new StatusStrip(); StatusStripR.Items.Add(new ToolStripStatusLabel()); panelS.Controls.Add(StatusStripL, 0, 0); panelS.Controls.Add(StatusStripR, 1, 0); Controls.Add(panelS); // // Menu area // var menuStrip1 = new MenuStrip(); menuStrip1.AutoSize = false; menuStrip1.Height = Config.MenuHeight; // user initialization and menu items IntInterface.CallBack.InitializeCallout(menuStrip1); var eventHandler = new ToolStripItemClickedEventHandler(ToolStripMenuItem_DropDownItemClicked); foreach (ToolStripMenuItem item in menuStrip1.Items) { item.DropDownItemClicked += eventHandler; } Controls.Add(menuStrip1); }
public MainForm() { Instance = this; InitializeComponent(); // Optimize panel drawing typeof(Panel).InvokeMember("DoubleBuffered", BindingFlags.SetProperty | BindingFlags.Instance | BindingFlags.NonPublic, null, Design, new object[] { true }); // Setup paths Func <string, string> fixPath = delegate(string path) { path = path.Replace('/', '\\'); if (!path.EndsWith("\\")) { path += "\\"; } return(Path.GetFullPath(path)); }; IniFile config = new IniFile(".\\FOnline.cfg"); Utilites.GuiPath = fixPath(config.IniReadValue("Options", "GuiPath", @"")); Utilites.GuiOutputPath = fixPath(config.IniReadValue("Options", "GuiOutputPath", @"")); Utilites.GuiResourcesPath = fixPath(config.IniReadValue("Options", "GuiResourcesPath", @"")); // Load default scheme LoadScheme(Utilites.GuiPath + "Default.foguischeme"); // Hierarchy drag and drop Hierarchy.ItemDrag += delegate(object sender, ItemDragEventArgs e) { DoDragDrop(e.Item, DragDropEffects.Move); }; Hierarchy.DragEnter += delegate(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; }; Hierarchy.DragDrop += delegate(object sender, DragEventArgs e) { if (e.Data.GetDataPresent("System.Windows.Forms.TreeNode", false)) { TreeView tree = (TreeView)sender; Point pt = tree.PointToClient(new Point(e.X, e.Y)); TreeNode destNode = tree.GetNodeAt(pt); TreeNode srcNode = (TreeNode)e.Data.GetData("System.Windows.Forms.TreeNode"); if (srcNode.Parent != null && destNode != null && srcNode != destNode && ((GUIObject)srcNode.Tag).Find(((GUIObject)destNode.Tag).Name) == null) { ((GUIObject)srcNode.Tag).AssignParent((GUIObject)destNode.Tag); } } }; // Hierarchy node selection Hierarchy.NodeMouseClick += delegate(object sender, TreeNodeMouseClickEventArgs e) { Hierarchy.SelectedNode = e.Node; Design.Invalidate(); }; Hierarchy.AfterSelect += delegate(object sender, TreeViewEventArgs e) { Properties.SelectedObject = e.Node.Tag; Design.Invalidate(); }; // Hierarchy menu strip ToolStripMenuItem addMenuStrip = new ToolStripMenuItem("Add"); addMenuStrip.DropDownItems.Add("Panel").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIPanel(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Button").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIButton(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("CheckBox").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUICheckBox(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("RadioButton").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIRadioButton(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Text").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIText(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Text Input").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUITextInput(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Message Box").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIMessageBox(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Console").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIConsole(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Grid").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIGrid(obj).RefreshRepresentation(false); }; addMenuStrip.DropDownItems.Add("Item View").Tag = (Action <GUIObject>) delegate(GUIObject obj) { new GUIItemView(obj).RefreshRepresentation(false); }; ToolStripMenuItem convertMenuStrip = new ToolStripMenuItem("Convert"); convertMenuStrip.DropDownItems.Add("Panel").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIPanel(obj)); }; convertMenuStrip.DropDownItems.Add("Button").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIButton(obj)); }; convertMenuStrip.DropDownItems.Add("CheckBox").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUICheckBox(obj)); }; convertMenuStrip.DropDownItems.Add("RadioButton").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIRadioButton(obj)); }; convertMenuStrip.DropDownItems.Add("Text").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIText(obj)); }; convertMenuStrip.DropDownItems.Add("Text Input").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUITextInput(obj)); }; convertMenuStrip.DropDownItems.Add("Message Box").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIMessageBox(obj)); }; convertMenuStrip.DropDownItems.Add("Console").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIConsole(obj)); }; convertMenuStrip.DropDownItems.Add("Grid").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIGrid(obj)); }; convertMenuStrip.DropDownItems.Add("Item View").Tag = (Func <GUIObject, GUIObject>) delegate(GUIObject obj) { return(new GUIItemView(obj)); }; ToolStripMenuItem moveUpMenuStrip = new ToolStripMenuItem("Move node up"); moveUpMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null) { obj.MoveUp(); } }; ToolStripMenuItem moveDownMenuStrip = new ToolStripMenuItem("Move node down"); moveDownMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null) { obj.MoveDown(); } }; ToolStripMenuItem deleteMenuStrip = new ToolStripMenuItem("Delete node"); deleteMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { if (obj != null) { obj.Delete(); } }; ToolStripMenuItem newTreeMenuStrip = new ToolStripMenuItem("New GUI"); newTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { NewTree(); }; ToolStripMenuItem loadTreeMenuStrip = new ToolStripMenuItem("Load GUI"); loadTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { LoadAndShowTree(); }; ToolStripMenuItem saveTreeMenuStrip = new ToolStripMenuItem("Save GUI"); saveTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SaveTree(obj, false); GenerateScheme(); }; ToolStripMenuItem saveAsTreeMenuStrip = new ToolStripMenuItem("Save GUI As"); saveAsTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SaveTree(obj, true); GenerateScheme(); }; ToolStripMenuItem setCoordsTreeMenuStrip = new ToolStripMenuItem("Set Coords"); setCoordsTreeMenuStrip.Tag = (Action <GUIObject>) delegate(GUIObject obj) { SetCoords(); }; ContextMenuStrip hierarchyMenuStrip = new ContextMenuStrip(); hierarchyMenuStrip.Items.Add(addMenuStrip); hierarchyMenuStrip.Items.Add(convertMenuStrip); hierarchyMenuStrip.Items.Add(moveUpMenuStrip); hierarchyMenuStrip.Items.Add(moveDownMenuStrip); hierarchyMenuStrip.Items.Add(deleteMenuStrip); hierarchyMenuStrip.Items.Add(newTreeMenuStrip); hierarchyMenuStrip.Items.Add(loadTreeMenuStrip); hierarchyMenuStrip.Items.Add(saveTreeMenuStrip); hierarchyMenuStrip.Items.Add(saveAsTreeMenuStrip); hierarchyMenuStrip.Items.Add(setCoordsTreeMenuStrip); ToolStripItemClickedEventHandler clickHandler = delegate(object sender, ToolStripItemClickedEventArgs e) { if (e.ClickedItem.Tag != null) { hierarchyMenuStrip.Close(); GUIObject curObj = (Hierarchy.SelectedNode != null ? (GUIObject)Hierarchy.SelectedNode.Tag : null); if (convertMenuStrip.DropDownItems.Contains(e.ClickedItem)) { if (curObj != null) { curObj.Delete(); GUIObject newObj = ((Func <GUIObject, GUIObject>)e.ClickedItem.Tag)(curObj.GetParent()); newObj.RefreshRepresentation(false); while (curObj.Children.Count > 0) { curObj.Children[0].AssignParent(newObj); } if (curObj.GetParent() == null) { LoadedTree = newObj; } List <FieldInfo> sourceFields = GetAllFields(curObj.GetType()); List <FieldInfo> destFields = GetAllFields(newObj.GetType()); foreach (FieldInfo fi in destFields) { if (destFields.FindIndex(fi2 => fi2.Name == fi.Name) != -1 && fi.Name != "_HierarchyNode" && fi.Name != "_Children") { fi.SetValue(newObj, fi.GetValue(curObj)); } } newObj.RefreshRepresentation(false); } else { MessageBox.Show("Create or load GUI first."); } } else { if (curObj == null && addMenuStrip.DropDownItems.Contains(e.ClickedItem)) { MessageBox.Show("Create or load GUI first."); } else { ((Action <GUIObject>)e.ClickedItem.Tag)(curObj); } } } }; addMenuStrip.DropDownItemClicked += clickHandler; convertMenuStrip.DropDownItemClicked += clickHandler; hierarchyMenuStrip.ItemClicked += clickHandler; Hierarchy.ContextMenuStrip = hierarchyMenuStrip; // Design drag handler bool designDragging = false; Point designDragMouseStart = Point.Empty; Point designDragObjectStart = Point.Empty; Design.MouseDown += delegate(object sender, MouseEventArgs e) { if (Hierarchy.SelectedNode != null) { GUIObject obj = (GUIObject)Hierarchy.SelectedNode.Tag; if (obj.IsHit(e.X, e.Y)) { designDragging = true; designDragMouseStart = new Point(e.X, e.Y); designDragObjectStart = obj.Position; Design.Capture = true; } } }; Design.MouseUp += delegate(object sender, MouseEventArgs e) { designDragging = false; Design.Capture = false; }; Design.MouseMove += delegate(object sender, MouseEventArgs e) { if (designDragging && Hierarchy.SelectedNode != null) { GUIObject obj = (GUIObject)Hierarchy.SelectedNode.Tag; Point position = obj.Position; position.X = designDragObjectStart.X + e.X - designDragMouseStart.X; position.Y = designDragObjectStart.Y + e.Y - designDragMouseStart.Y; obj.Position = position; Properties.Refresh(); Design.Refresh(); } }; }
public static void PopulateToolStripMenuWithDBEntries(ToolStripItemCollection itemCollection, Type dbEntryType, ToolStripItemClickedEventHandler onClickEventHandler = null, bool addRandomOption = false, string tagPrefix = "") { if (addRandomOption) { itemCollection.Add("(Random)").Tag = ""; } foreach (string id in Database.Instance.GetAllEntriesIDs(dbEntryType)) { ToolStripItemCollection parentCollection = itemCollection; DBEntry dbEntry = Database.Instance.GetEntry(dbEntryType, id); if (dbEntry == null) { continue; } if (!string.IsNullOrEmpty(dbEntry.UICategory)) // Database entry belong to a collection { string categoryName = dbEntry.UICategory; string categoryID = "*" + dbEntry.UICategory; if (!parentCollection.ContainsKey(categoryID)) { ToolStripItem categoryItem = parentCollection.Add(categoryName); categoryItem.Name = categoryID; categoryItem.BackColor = BLUEPRINT_BACKCOLOR_MENU; categoryItem.Font = BLUEPRINT_FONT; categoryItem.ForeColor = BLUEPRINT_FORECOLOR; } parentCollection = ((ToolStripMenuItem)parentCollection[categoryID]).DropDownItems; } ToolStripMenuItem item = new ToolStripMenuItem { Text = dbEntry.UIDisplayName, ToolTipText = dbEntry.UIDescription, Tag = tagPrefix + id, BackColor = BLUEPRINT_BACKCOLOR_MENU, Font = BLUEPRINT_FONT, ForeColor = BLUEPRINT_FORECOLOR, }; parentCollection.Add(item); } foreach (ToolStripMenuItem item in itemCollection) { if (item.DropDownItems.Count > 0) { if (onClickEventHandler != null) { item.DropDownItemClicked += onClickEventHandler; } SortContextMenuStrip(item.DropDownItems); } } SortContextMenuStrip(itemCollection); }
public MyUserControl(ToolStripItemClickedEventHandler handler) { InitializeComponent(); myContextMenuStrip.ItemClicked += handler; }
private void AddNodeEnumToPropertyGrid(string title, string value, object tag, TreeNode parent, ToolStripItemClickedEventHandler handler) { AddNodeEnumToPropertyGrid(title, value, tag, parent, handler, false); }
/// <summary> /// Open a context menu. /// </summary> /// <param name="theme">Visual Theme</param> /// <param name="items">Items to be listed</param> /// <param name="mouse"></param> /// <param name="selectHandler">Handler that will handle when an item is clicked</param> public static void OpenContextPopup(ITheme theme, ToolStripItemCollection items, MouseEventArgs mouse, ToolStripItemClickedEventHandler selectHandler) { ContextMenuStrip menuStrip = new ContextMenuStrip(); menuStrip.Items.AddRange(items); menuStrip.ItemClicked += delegate(object sender, ToolStripItemClickedEventArgs e) { selectHandler(e.ClickedItem, e); }; menuStrip.Show(mouse.Location); }
public override void CreateContextMenu(ContextMenuStrip contextMenu, ToolStripItemClickedEventHandler onClickEventHandler) { ToolStripMenuItem parentMenu; // Flyable aircraft parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("Aircraft"); GUITools.PopulateToolStripMenuWithDBEntries(parentMenu.DropDownItems, typeof(DBPseudoEntryPlayerAircraft), onClickEventHandler); // Aircraft count parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("Aircraft count"); GUITools.PopulateToolStripMenuWithIntegers(parentMenu.DropDownItems, 1, Toolbox.MAXIMUM_FLIGHT_GROUP_SIZE); // Flight group tasking parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("Tasking"); foreach (object enumValue in Enum.GetValues(typeof(MissionTemplateFlightGroupTask))) { GUITools.GetDisplayStrings(typeof(MissionTemplateFlightGroupTask), enumValue, out string enumDisplayName, out string enumDescription); ToolStripMenuItem item = new ToolStripMenuItem { Text = enumDisplayName, Tag = enumValue, ToolTipText = enumDescription }; parentMenu.DropDownItems.Add(item); } // Aircraft carriers parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("Home carrier"); parentMenu.DropDownItems.Add("(None, take off from land airbase)").Tag = "$"; GUITools.PopulateToolStripMenuWithDBEntries(parentMenu.DropDownItems, typeof(DBPseudoEntryCarrier), onClickEventHandler, false, "$"); // Country //TODO Grouping parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("Country"); foreach (object enumValue in Enum.GetValues(typeof(Country))) { GUITools.GetDisplayStrings(typeof(Country), enumValue, out string enumDisplayName, out string enumDescription); ToolStripMenuItem item = new ToolStripMenuItem { Text = enumDisplayName, Tag = enumValue, ToolTipText = enumDescription }; parentMenu.DropDownItems.Add(item); } // Country //TODO Grouping parentMenu = (ToolStripMenuItem)contextMenu.Items.Add("StartLocation"); foreach (object enumValue in Enum.GetValues(typeof(PlayerStartLocation))) { GUITools.GetDisplayStrings(typeof(PlayerStartLocation), enumValue, out string enumDisplayName, out string enumDescription); ToolStripMenuItem item = new ToolStripMenuItem { Text = enumDisplayName, Tag = enumValue, ToolTipText = enumDescription }; parentMenu.DropDownItems.Add(item); } }