本文整理汇总了C#中System.Windows.Forms.Menu类的典型用法代码示例。如果您正苦于以下问题:C# Menu类的具体用法?C# Menu怎么用?C# Menu使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Menu类属于System.Windows.Forms命名空间,在下文中一共展示了Menu类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMyMenu
public void CreateMyMenu()
{
// Set the caption for the top-level menu item.
menuItem1.Text = "Edit";
// Set the caption for the first submenu.
menuItem2.Text = "Font Size";
// Set the caption for menuItem2's first submenu.
menuItem3.Text = "Small";
// Set the checked property to true since this is the default value.
menuItem3.Checked = true;
// Define a shortcut key combination for the menu item.
menuItem3.Shortcut = Shortcut.CtrlS;
// Set the caption of the second sub menu item of menuItem2.
menuItem4.Text = "Large";
// Define a shortcut key combination for the menu item.
menuItem4.Shortcut = Shortcut.CtrlL;
// Set the index of the menu item so it is placed below the first submenu item.
menuItem4.Index = 1;
// Add menuItem3 and menuItem4 to menuItem2's list of menu items.
menuItem2.MenuItems.Add(menuItem3);
menuItem2.MenuItems.Add(menuItem4);
// Add menuItem2 to menuItem1's list of menu items.
menuItem1.MenuItems.Add(menuItem2);
// Add menuItem1 to the MainMenu for displaying.
mainMenu1.MenuItems.Add(menuItem1);
}