本文整理汇总了C#中System.Windows.Forms.MenuItem.Click事件的典型用法代码示例。如果您正苦于以下问题:C# MenuItem.Click事件的具体用法?C# MenuItem.Click怎么用?C# MenuItem.Click使用的例子?那么, 这里精选的事件代码示例或许可以为您提供帮助。您也可以进一步了解该事件所在类System.Windows.Forms.MenuItem
的用法示例。
在下文中一共展示了MenuItem.Click事件的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: CreateMyMenu
public void CreateMyMenu()
{
// Create a main menu object.
MainMenu mainMenu1 = new MainMenu();
// Create empty menu item objects.
MenuItem topMenuItem = new MenuItem();
MenuItem menuItem1 = new MenuItem();
// Set the caption of the menu items.
topMenuItem.Text = "&File";
menuItem1.Text = "&Open";
// Add the menu items to the main menu.
topMenuItem.MenuItems.Add(menuItem1);
mainMenu1.MenuItems.Add(topMenuItem);
// Add functionality to the menu items using the Click event.
menuItem1.Click += new System.EventHandler(this.menuItem1_Click);
// Assign mainMenu1 to the form.
this.Menu=mainMenu1;
}
private void menuItem1_Click(object sender, System.EventArgs e)
{
// Create a new OpenFileDialog and display it.
OpenFileDialog fd = new OpenFileDialog();
fd.DefaultExt = "*.*";
fd.ShowDialog();
}
示例2: Main
//引入命名空间
using System;
using System.Drawing;
using System.Drawing.Imaging;
using System.Windows.Forms;
class ImageClip : Form {
MenuItem miCut, miCopy, miPaste, miDel;
Image image;
public static void Main() {
Application.Run(new ImageClip());
}
public ImageClip() {
Text = "Image Clip";
MenuItem mi = new MenuItem("&Edit");
mi.Popup += new EventHandler(MenuEditOnPopup);
Menu.MenuItems.Add(mi);
int index = Menu.MenuItems.Count - 1;
miCut = new MenuItem("Cu&t");
miCut.Click += new EventHandler(MenuEditCutOnClick);
miCut.Shortcut = Shortcut.CtrlX;
Menu.MenuItems[index].MenuItems.Add(miCut);
miCopy = new MenuItem("&Copy");
miCopy.Click += new EventHandler(MenuEditCopyOnClick);
miCopy.Shortcut = Shortcut.CtrlC;
Menu.MenuItems[index].MenuItems.Add(miCopy);
miPaste = new MenuItem("&Paste");
miPaste.Click += new EventHandler(MenuEditPasteOnClick);
miPaste.Shortcut = Shortcut.CtrlV;
Menu.MenuItems[index].MenuItems.Add(miPaste);
miDel = new MenuItem("De&lete");
miDel.Click += new EventHandler(MenuEditDelOnClick);
miDel.Shortcut = Shortcut.Del;
Menu.MenuItems[index].MenuItems.Add(miDel);
}
void MenuEditOnPopup(object obj, EventArgs ea) {
miCut.Enabled = miCopy.Enabled = miDel.Enabled = image != null;
IDataObject data = Clipboard.GetDataObject();
miPaste.Enabled = data.GetDataPresent(typeof(Bitmap)) || data.GetDataPresent(typeof(Metafile));
}
void MenuEditCutOnClick(object obj, EventArgs ea) {
MenuEditCopyOnClick(obj, ea);
MenuEditDelOnClick(obj, ea);
}
void MenuEditCopyOnClick(object obj, EventArgs ea) {
Clipboard.SetDataObject(image, true);
}
void MenuEditPasteOnClick(object obj, EventArgs ea) {
IDataObject data = Clipboard.GetDataObject();
if (data.GetDataPresent(typeof(Metafile)))
image = (Image)data.GetData(typeof(Metafile));
else if (data.GetDataPresent(typeof(Bitmap)))
image = (Image)data.GetData(typeof(Bitmap));
Invalidate();
}
void MenuEditDelOnClick(object obj, EventArgs ea) {
image = null;
Invalidate();
}
}