本文整理汇总了C#中System.Windows.Forms.MenuItem类的典型用法代码示例。如果您正苦于以下问题:C# MenuItem类的具体用法?C# MenuItem怎么用?C# MenuItem使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
MenuItem类属于System.Windows.Forms命名空间,在下文中一共展示了MenuItem类的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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);
}
开发者ID:.NET开发者,项目名称:System.Windows.Forms,代码行数:26,代码来源:MenuItem
示例2: new MenuItem
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class OldFashionedMenu: Form
{
MainMenu mmMain, mmFile, mmEdit;
public static void Main()
{
Application.Run(new OldFashionedMenu());
}
public OldFashionedMenu()
{
EventHandler eh = new EventHandler(MenuOnClick);
mmMain = new MainMenu(new MenuItem[]
{
new MenuItem("MAIN:"),
new MenuItem("&File", new EventHandler(MenuFileOnClick)),
new MenuItem("&Edit", new EventHandler(MenuEditOnClick))
});
mmFile = new MainMenu(new MenuItem[]
{
new MenuItem("FILE:"),
new MenuItem("&New", eh),
new MenuItem("&Open...", eh),
new MenuItem("&Save", eh),
new MenuItem("Save &As...", eh),
new MenuItem("(&Main)", new EventHandler(MenuMainOnClick))
});
mmEdit = new MainMenu(new MenuItem[]
{
new MenuItem("EDIT:"),
new MenuItem("Cu&t", eh),
new MenuItem("&Copy", eh),
new MenuItem("&Paste", eh),
new MenuItem("De&lete", eh),
new MenuItem("(&Main)", new EventHandler(MenuMainOnClick))
});
Menu = mmMain;
}
void MenuMainOnClick(object obj, EventArgs ea)
{
Menu = mmMain;
}
void MenuFileOnClick(object obj, EventArgs ea)
{
Menu = mmFile;
}
void MenuEditOnClick(object obj, EventArgs ea)
{
Menu = mmEdit;
}
void MenuOnClick(object obj, EventArgs ea)
{
MessageBox.Show("Menu item clicked!", Text);
}
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:63,代码来源:MenuItem
示例3: new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class FirstMainMenu: Form
{
public static void Main()
{
Application.Run(new FirstMainMenu());
}
public FirstMainMenu()
{
MenuItem miOpen = new MenuItem("&Open...",
new EventHandler(MenuFileOpenOnClick),
Shortcut.CtrlO);
MenuItem miSave = new MenuItem("&Save",
new EventHandler(MenuFileSaveOnClick),
Shortcut.CtrlS);
MenuItem miSaveAs = new MenuItem("Save &As...",
new EventHandler(MenuFileSaveAsOnClick));
MenuItem miDash = new MenuItem("-");
MenuItem miExit = new MenuItem("E&xit",
new EventHandler(MenuFileExitOnClick));
MenuItem miFile = new MenuItem("&File",
new MenuItem[] {miOpen, miSave, miSaveAs,
miDash, miExit });
MenuItem miCut = new MenuItem("Cu&t",
new EventHandler(MenuEditCutOnClick),
Shortcut.CtrlX);
MenuItem miCopy = new MenuItem("&Copy",
new EventHandler(MenuEditCopyOnClick),
Shortcut.CtrlC);
MenuItem miPaste = new MenuItem("&Paste",
new EventHandler(MenuEditPasteOnClick),
Shortcut.CtrlV);
MenuItem miEdit = new MenuItem("&Edit",
new MenuItem[] {miCut, miCopy, miPaste});
MenuItem miAbout = new MenuItem("&About FirstMainMenu...",
new EventHandler(MenuHelpAboutOnClick));
MenuItem miHelp = new MenuItem("&Help",
new MenuItem[] {miAbout});
Menu = new MainMenu(new MenuItem[] {miFile, miEdit, miHelp});
}
void MenuFileOpenOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File Open item clicked!", Text);
}
void MenuFileSaveOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File Save item clicked!", Text);
}
void MenuFileSaveAsOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File Save As item clicked!", Text);
}
void MenuFileExitOnClick(object obj, EventArgs ea)
{
Close();
}
void MenuEditCutOnClick(object obj, EventArgs ea)
{
MessageBox.Show("Edit Cut item clicked!", Text);
}
void MenuEditCopyOnClick(object obj, EventArgs ea)
{
MessageBox.Show("Edit Copy item clicked!", Text);
}
void MenuEditPasteOnClick(object obj, EventArgs ea)
{
MessageBox.Show("Edit Paste item clicked!", Text);
}
void MenuHelpAboutOnClick(object obj, EventArgs ea)
{
MessageBox.Show(Text + " ?");
}
}
开发者ID:C#程序员,项目名称:System.Windows.Forms,代码行数:86,代码来源:MenuItem
注:本文中的System.Windows.Forms.MenuItem类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论