private void FrmMain_Load(object sender, System.EventArgs e) { contextMenu.MergeMenu(menuEdit); txtContent.ContextMenu = contextMenu; //stbTime.Text = System.DateTime.Now.ToString(); }
/// <summary> /// /// </summary> /// <param name="e"></param> protected override void OnMouseDown(MouseEventArgs e) { if (Focused == false) this.Focus(); // clear the mouse data holders m_oMouseClickPoint.X = e.X; m_oMouseClickPoint.Y = e.Y; m_oButtonClicked = e.Button; // check if have not clicked the right corner when scrollbars are in place if (Controls.Contains(m_oHScrollBar) && Controls.Contains(m_oScrollBar)) { if (m_oMouseClickPoint.X > m_oHScrollBar.Right && m_oMouseClickPoint.Y > m_oScrollBar.Bottom) { // redraw the control Invalidate(); return; } } // check the place, get the object, its popup menu and show it Component oComponent = this.GetSubObjectAtPoint(m_oMouseClickPoint); if (oComponent is Node) InvokeNodeMouseDown(e, oComponent as Node); // flag object if (this.Flags == true && IsNodeFlag(m_oMouseClickPoint) == true) { Node oNode = GetNodeByItemFlag(GetNodeFlagRect(m_oMouseClickPoint)); InvokeNodeFlagMouseDown(e, oNode); } #region node select if (oComponent is Node) { // get the node Node oNode = oComponent as Node; // make the node selected oNode.Select(m_Control, m_Shift); // set the focus node m_oFocusNode = oNode; // redraw the node oNode.Invalidate(); } #endregion if (m_oButtonClicked == MouseButtons.Right) { if (this.ContextMenuStrip != null) { ContextMenuExtensionTreeView(this.ContextMenuStrip); this.ContextMenuStrip.Show(this, m_oMouseClickPoint); return; } if (oComponent is Node) { Node oNode = oComponent as Node; ContextMenu oMenu = oNode.GetContextMenu(); if (oMenu == null && this.ContextMenuArranging == false && this.ContextMenuEditing == false && this.ContextMenuXmlOperations == false) return; if (oMenu == null && (this.ContextMenuArranging == true || this.ContextMenuEditing == true || this.ContextMenuXmlOperations == true)) oMenu = new ContextMenu(); ContextMenu contextMenu = new ContextMenu(); try { m_OnPopupMenu.Invoke(oMenu, new object[] {EventArgs.Empty}); } catch { } contextMenu.MergeMenu(oMenu); // check the associated menu switches, if we have several menu alterations specified, use them to add // proper menu items which are associated with menu commands that have predefined handlers ContextMenuExtension(contextMenu); contextMenu.Show(this, m_oMouseClickPoint); return; } this.SelectedNode = null; // context menu associated with the treeview and being called ContextMenu oContMenu = this.ContextMenu; if (oContMenu == null && (this.ContextMenuArranging == true || this.ContextMenuEditing == true || this.ContextMenuXmlOperations == true)) oContMenu = new ContextMenu(); if (oContMenu != null) { ContextMenu contextMenu = new ContextMenu(); try { m_OnPopupMenu.Invoke(oContMenu, new object[] {EventArgs.Empty}); } catch { } contextMenu.MergeMenu(oContMenu); // check the associated menu switches, if we have several menu alterations specified, use them to add // proper menu items which are associated with menu commands that have predefined handlers ContextMenuExtensionTreeView(contextMenu); contextMenu.Show(this, m_oMouseClickPoint); return; } } base.OnMouseDown(e); }
/// <summary> /// Based on the treeview settings adds new commands of the menu object /// </summary> /// <param name="contextMenu"></param> private void ContextMenuExtensionTreeView(ContextMenu contextMenu) { if (this.ContextMenuEditing == true) { ContextMenu contextMenuEditing = new ContextMenu(); if ((AllowAdding == true || AllowEditing == true) && contextMenu.MenuItems.Count > 0) contextMenuEditing.MenuItems.Add("-"); if (AllowAdding == true) contextMenuEditing.MenuItems.Add(m_oContextMenuString.AddNode, new EventHandler(OnContextMenuEditingAddNode)); if (AllowEditing == true) contextMenuEditing.MenuItems.Add(m_oContextMenuString.Paste, new EventHandler(OnContextMenuEditingPaste)); contextMenu.MergeMenu(contextMenuEditing); } if (this.ContextMenuArranging == true) { ContextMenu contextMenuArranging = new ContextMenu(); if (contextMenu.MenuItems.Count > 0) contextMenuArranging.MenuItems.Add("-"); contextMenuArranging.MenuItems.Add(m_oContextMenuString.Expand, new EventHandler(OnContextMenuArrangingExpand)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.Collapse, new EventHandler(OnContextMenuArrangingCollapse)); contextMenu.MergeMenu(contextMenuArranging); } if (this.ContextMenuXmlOperations == true) { ContextMenu contextMenuXmlOperations = new ContextMenu(); if (contextMenu.MenuItems.Count > 0) contextMenuXmlOperations.MenuItems.Add("-"); contextMenuXmlOperations.MenuItems.Add(m_oContextMenuString.SaveXml, new EventHandler(OnContextMenuXmlOperationsSave)); contextMenuXmlOperations.MenuItems.Add(m_oContextMenuString.LoadXml, new EventHandler(OnContextMenuXmlOperationsLoad)); contextMenu.MergeMenu(contextMenuXmlOperations); } }
/// <summary> /// Based on the treeview settings adds new commands of the menu object /// </summary> /// <param name="contextMenu"></param> private void ContextMenuExtension(ContextMenu contextMenu) { if (this.ContextMenuEditing == true) { if ((AllowAdding == true || AllowDeleting == true || LabelEdit == true || AllowEditing == true) && contextMenu.MenuItems.Count > 0) contextMenu.MenuItems.Add("-"); if (AllowAdding == true) contextMenu.MenuItems.Add(m_oContextMenuString.AddNode, new EventHandler(OnContextMenuEditingAddNode)); if (AllowDeleting == true) contextMenu.MenuItems.Add(m_oContextMenuString.DeleteNode, new EventHandler(OnContextMenuEditingDeleteNode)); if (LabelEdit == true) contextMenu.MenuItems.Add(m_oContextMenuString.EditNode, new EventHandler(OnContextMenuEditingEditNode)); if (AllowEditing == true) contextMenu.MenuItems.Add(m_oContextMenuString.Copy, new EventHandler(OnContextMenuEditingCopy)); if (AllowEditing == true) contextMenu.MenuItems.Add(m_oContextMenuString.Paste, new EventHandler(OnContextMenuEditingPaste)); } if (this.ContextMenuArranging == true) { ContextMenu contextMenuArranging = new ContextMenu(); if (contextMenu.MenuItems.Count > 0) contextMenuArranging.MenuItems.Add("-"); contextMenuArranging.MenuItems.Add(m_oContextMenuString.Expand, new EventHandler(OnContextMenuArrangingExpand)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.Collapse, new EventHandler(OnContextMenuArrangingCollapse)); if (AllowArranging == true) { contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveTop, new EventHandler(OnContextMenuArrangingMoveTop)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveBottom, new EventHandler(OnContextMenuArrangingMoveBottom)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveUp, new EventHandler(OnContextMenuArrangingMoveUp)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveDown, new EventHandler(OnContextMenuArrangingMoveDown)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveLeft, new EventHandler(OnContextMenuArrangingMoveLeft)); contextMenuArranging.MenuItems.Add(m_oContextMenuString.MoveRight, new EventHandler(OnContextMenuArrangingMoveRight)); } contextMenu.MergeMenu(contextMenuArranging); } if (this.ContextMenuXmlOperations == true) { ContextMenu contextMenuXmlOperations = new ContextMenu(); if (contextMenu.MenuItems.Count > 0) contextMenuXmlOperations.MenuItems.Add("-"); contextMenuXmlOperations.MenuItems.Add(m_oContextMenuString.SaveXml, new EventHandler(OnContextMenuXmlOperationsSave)); contextMenuXmlOperations.MenuItems.Add(m_oContextMenuString.LoadXml, new EventHandler(OnContextMenuXmlOperationsLoad)); contextMenu.MergeMenu(contextMenuXmlOperations); } }
public Form1() : base() { this.mainMenu1 = new System.Windows.Forms.MainMenu(); this.fileItem = new System.Windows.Forms.MenuItem(); this.newItem = new System.Windows.Forms.MenuItem(); this.openItem = new System.Windows.Forms.MenuItem(); this.saveItem = new System.Windows.Forms.MenuItem(); this.viewItem = new System.Windows.Forms.MenuItem(); this.toolsItem = new System.Windows.Forms.MenuItem(); this.optionsMenu = new System.Windows.Forms.MenuItem(); this.toolsItem = new System.Windows.Forms.MenuItem(); this.viewItem = new System.Windows.Forms.MenuItem(); this.contextMenu1 = new System.Windows.Forms.ContextMenu(); this.cutItem = new System.Windows.Forms.MenuItem(); this.copyItem = new System.Windows.Forms.MenuItem(); this.pasteItem = new System.Windows.Forms.MenuItem(); //Add file menu item and options menu item to the MainMenu. this.mainMenu1.MenuItems.AddRange( new System.Windows.Forms.MenuItem[] { this.fileItem, this.optionsMenu }); // Initialize the file menu and its contents. this.fileItem.Index = 0; this.fileItem.Text = "File"; this.newItem.Index = 0; this.newItem.Text = "New"; this.openItem.Index = 1; this.openItem.Text = "Open"; this.saveItem.Index = 2; this.saveItem.Text = "Save"; // Set the merge order of fileItem to 2 so it has a lower priority // on the merged menu. this.fileItem.MergeOrder = 2; //Add the new items to the fileItem menu item collection. this.fileItem.MenuItems.AddRange(new MenuItem[] { this.newItem, this.openItem, this.saveItem }); // Initalize the optionsMenu item and its contents. this.optionsMenu.Index = 1; this.optionsMenu.Text = "Options"; this.viewItem.Index = 0; this.viewItem.Text = "View"; this.toolsItem.Index = 1; this.toolsItem.Text = "Tools"; // Set mergeOrder property to 1, so it has a higher priority than // the fileItem on the merged menu. this.optionsMenu.MergeOrder = 1; //Add view and tool items to the optionsItem menu item. this.optionsMenu.MenuItems.AddRange(new MenuItem[] { this.viewItem, this.toolsItem }); // Initialize the menu items for the shortcut menu. this.cutItem.Index = 0; this.cutItem.Text = "Cut"; this.cutItem.MergeOrder = 0; this.copyItem.Index = 1; this.copyItem.Text = "Copy"; this.copyItem.MergeOrder = 0; this.pasteItem.Index = 2; this.pasteItem.Text = "Paste"; this.pasteItem.MergeOrder = 0; // Add menu items to the shortcut menu. this.contextMenu1.MenuItems.AddRange(new MenuItem[] { cutItem, copyItem, pasteItem }); // Add the mainMenu1 items to the shortcut menu as well, by // calling the MergeMenu method. contextMenu1.MergeMenu(mainMenu1); //Initialize the form. this.ClientSize = new System.Drawing.Size(292, 266); this.Name = "Form1"; this.Text = "Right click on form for merged menu."; // Associate the event-handling method with the // MouseDown event. this.MouseDown += new MouseEventHandler(Form1_MouseDown); // Add mainMenu1 to the form. this.Menu = mainMenu1; }
public void MenuItemMerge () { MenuItem item1 = new MenuItem ("File (0)"); // Position 0 MenuItem item2 = new MenuItem ("Print the file (1)"); // Position 1 MenuItem item3 = new MenuItem ("Print Preview (2)"); // Position 2 MenuItem item4 = new MenuItem ("-"); // Position 3 MenuItem item5 = new MenuItem ("Recent files (4)"); // Position 4 MenuItem item6 = new MenuItem ("Exit (5)"); // Position 5 MenuItem item10 = new MenuItem ("Compare... (6)"); // Replace pos 3 MenuItem item11 = new MenuItem ("Sort (7)"); MenuItem item12 = new MenuItem ("Conversions (8)"); MenuItem item13 = new MenuItem ("Specials Functions (9)"); MenuItem item14 = new MenuItem ("Another option... (10)"); MenuItem item20 = new MenuItem ("autors.doc"); MenuItem item21 = new MenuItem ("testing.html"); MenuItem item22 = new MenuItem ("proves.txt"); MenuItem[] first_items = new MenuItem[] {item1, item2, item3, item4, item5, item6}; MenuItem[] second_items = new MenuItem[] {item10, item11, item12, item13, item14}; MenuItem[] third_items = new MenuItem[] {item20, item21, item22}; item14.MergeType = MenuMerge.Remove; item10.MergeOrder = 40; item11.MergeType = MenuMerge.Replace; item11.MergeOrder = 30; item12.MergeOrder = 5; item10.MergeType = MenuMerge.MergeItems; ContextMenu first_menu = new ContextMenu (first_items); ContextMenu second_menu = new ContextMenu (second_items); ContextMenu third_menu = new ContextMenu (third_items); first_menu.MergeMenu (second_menu); first_menu.MergeMenu (third_menu); Assert.AreEqual ("File (0)", first_menu.MenuItems[0].Text, "ItemMerge#1"); Assert.AreEqual ("Print the file (1)", first_menu.MenuItems[1].Text, "ItemMerge#2"); Assert.AreEqual ("Print Preview (2)", first_menu.MenuItems[2].Text, "ItemMerge#3"); Assert.AreEqual ("-", first_menu.MenuItems[3].Text, "ItemMerge#4"); Assert.AreEqual ("Recent files (4)", first_menu.MenuItems[4].Text, "ItemMerge#5"); Assert.AreEqual ("Exit (5)", first_menu.MenuItems[5].Text, "ItemMerge#6"); Assert.AreEqual ("Specials Functions (9)", first_menu.MenuItems[6].Text, "ItemMerge#7"); Assert.AreEqual ("autors.doc", first_menu.MenuItems[7].Text, "ItemMerge#8"); Assert.AreEqual ("testing.html", first_menu.MenuItems[8].Text, "ItemMerge#9"); Assert.AreEqual ("proves.txt", first_menu.MenuItems[9].Text, "ItemMerge#10"); Assert.AreEqual ("Conversions (8)", first_menu.MenuItems[10].Text, "ItemMerge#11"); Assert.AreEqual ("Sort (7)", first_menu.MenuItems[11].Text, "ItemMerge#11"); Assert.AreEqual ("Compare... (6)", first_menu.MenuItems[12].Text, "ItemMerge#11"); }