本文整理汇总了C#中System.Windows.Forms.MenuItem.Shortcut属性的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.Shortcut属性的具体用法?C# MenuItem.Shortcut怎么用?C# MenuItem.Shortcut使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.Shortcut属性的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: SetupMyMenuItem
public void SetupMyMenuItem()
{
// Set the caption for the menu item.
menuItem1.Text = "&New";
// Assign a shortcut key.
menuItem1.Shortcut = Shortcut.CtrlN;
// Make the menu item visible.
menuItem1.Visible = true;
// Display the shortcut key combination.
menuItem1.ShowShortcut = true;
}
示例2: Main
//引入命名空间
using System;
using System.Drawing;
using System.Windows.Forms;
class StandardMenu: Form
{
MenuItem miFileOpen, miFileSave;
MenuItem miEditCut, miEditCopy, miEditPaste;
bool bDocumentPresent = true;
bool bNonNullSelection = true;
bool bStuffInClipboard = false;
public static void Main()
{
Application.Run(new StandardMenu());
}
public StandardMenu()
{
Menu = new MainMenu();
MenuItem mi = new MenuItem("&File");
mi.Popup += new EventHandler(MenuFileOnPopup);
Menu.MenuItems.Add(mi);
int index = Menu.MenuItems.Count - 1;
miFileOpen = new MenuItem("&Open...");
miFileOpen.Click += new EventHandler(MenuFileOpenOnClick);
miFileOpen.Shortcut = Shortcut.CtrlO;
Menu.MenuItems[index].MenuItems.Add(miFileOpen);
miFileSave = new MenuItem("&Save");
miFileSave.Click += new EventHandler(MenuFileSaveOnClick);
miFileSave.Shortcut = Shortcut.CtrlS;
Menu.MenuItems[index].MenuItems.Add(miFileSave);
mi = new MenuItem("-");
Menu.MenuItems[index].MenuItems.Add(mi);
mi = new MenuItem("E&xit");
mi.Click += new EventHandler(MenuFileExitOnClick);
Menu.MenuItems[index].MenuItems.Add(mi);
mi = new MenuItem("&Edit");
mi.Popup += new EventHandler(MenuEditOnPopup);
Menu.MenuItems.Add(mi);
index = Menu.MenuItems.Count - 1;
miEditCut = new MenuItem("Cu&t");
miEditCut.Click += new EventHandler(MenuEditCutOnClick);
miEditCut.Shortcut = Shortcut.CtrlX;
Menu.MenuItems[index].MenuItems.Add(miEditCut);
miEditCopy = new MenuItem("&Copy");
miEditCopy.Click += new EventHandler(MenuEditCopyOnClick);
miEditCopy.Shortcut = Shortcut.CtrlC;
Menu.MenuItems[index].MenuItems.Add(miEditCopy);
miEditPaste = new MenuItem("&Paste");
miEditPaste.Click += new EventHandler(MenuEditCopyOnClick);
miEditPaste.Shortcut = Shortcut.CtrlV;
Menu.MenuItems[index].MenuItems.Add(miEditPaste);
mi = new MenuItem("&Help");
Menu.MenuItems.Add(mi);
index = Menu.MenuItems.Count - 1;
mi = new MenuItem("&About StandardMenu...");
mi.Click += new EventHandler(MenuHelpAboutOnClick);
Menu.MenuItems[index].MenuItems.Add(mi);
}
void MenuFileOnPopup(object obj, EventArgs ea)
{
miFileSave.Enabled = bDocumentPresent;
}
void MenuEditOnPopup(object obj, EventArgs ea)
{
miEditCut.Enabled = bNonNullSelection;
miEditCopy.Enabled = bNonNullSelection;
miEditPaste.Enabled = bStuffInClipboard;
}
void MenuFileOpenOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File Open dialog box!", Text);
}
void MenuFileSaveOnClick(object obj, EventArgs ea)
{
MessageBox.Show("File Save dialog box!", Text);
}
void MenuFileExitOnClick(object obj, EventArgs ea)
{
Close();
}
void MenuEditCutOnClick(object obj, EventArgs ea)
{
}
void MenuEditCopyOnClick(object obj, EventArgs ea)
{
}
void MenuEditPasteOnClick(object obj, EventArgs ea)
{
}
void MenuHelpAboutOnClick(object obj, EventArgs ea)
{
MessageBox.Show("StandardMenu ?", Text);
}
}