本文整理汇总了C#中System.Windows.Forms.ContextMenu.MergeMenu方法的典型用法代码示例。如果您正苦于以下问题:C# ContextMenu.MergeMenu方法的具体用法?C# ContextMenu.MergeMenu怎么用?C# ContextMenu.MergeMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.ContextMenu
的用法示例。
在下文中一共展示了ContextMenu.MergeMenu方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: OnMouseDown
/// <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);
//.........这里部分代码省略.........
示例2: ContextMenuExtension
/// <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);
}
}
示例3: ContextMenuExtensionTreeView
/// <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);
}
}
示例4: MenuItemMerge
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");
}