本文整理汇总了C#中System.Windows.Forms.Menu.GetContextMenu方法的典型用法代码示例。如果您正苦于以下问题:C# Menu.GetContextMenu方法的具体用法?C# Menu.GetContextMenu怎么用?C# Menu.GetContextMenu使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Windows.Forms.Menu
的用法示例。
在下文中一共展示了Menu.GetContextMenu方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AddContextmenu
public void AddContextmenu()
{
// Create a shortcut menu.
ContextMenu m = new ContextMenu();
this.ContextMenu= m;
// Create MenuItem objects.
MenuItem menuItem1 = new MenuItem();
MenuItem menuItem2 = new MenuItem();
// Set the Text property.
menuItem1.Text = "New";
menuItem2.Text = "Open";
// Add menu items to the MenuItems collection.
m.MenuItems.Add(menuItem1);
m.MenuItems.Add(menuItem2);
// Display the starting message.
MessageBox.Show("Right-click the form to display the shortcut menu items");
// Add functionality to the menu items.
menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
menuItem2.Click += new System.EventHandler(this.menuItem2_Click);
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
string textReport = "You clicked the New menu item. \n" +
"It is contained in the following shortcut menu: \n\n";
// Get information on the shortcut menu in which menuitem1 is contained.
textReport += ContextMenu.GetContextMenu().ToString();
// Display the shortcut menu information in a message box.
MessageBox.Show(textReport,"The ContextMenu Information");
}
private void menuItem2_Click(object sender, System.EventArgs e)
{
string textReport = "You clicked the Open menu item. \n" +
"It is contained in the following shortcut menu: \n\n";
// Get information on the shortcut menu in which menuitem1 is contained.
textReport += ContextMenu.GetContextMenu().ToString();
// Display the shortcut menu information in a message box.
MessageBox.Show(textReport,"The ContextMenu Information");
}