new MenuItem() : MenuItem « GUI Windows Forms « C# / CSharp Tutorial

Home
C# / CSharp Tutorial
1.Language Basics
2.Data Type
3.Operator
4.Statement
5.String
6.struct
7.Class
8.Operator Overload
9.delegate
10.Attribute
11.Data Structure
12.Assembly
13.Date Time
14.Development
15.File Directory Stream
16.Preprocessing Directives
17.Regular Expression
18.Generic
19.Reflection
20.Thread
21.I18N Internationalization
22.LINQ
23.GUI Windows Forms
24.Windows Presentation Foundation
25.Windows Communication Foundation
26.Workflow
27.2D
28.Design Patterns
29.Windows
30.XML
31.XML LINQ
32.ADO.Net
33.Network
34.Directory Services
35.Security
36.unsafe
C# / C Sharp
C# / C Sharp by API
C# / CSharp Open Source
C# / CSharp Tutorial » GUI Windows Forms » MenuItem 
23.41.1.new MenuItem()
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 + " ?");
     }
}
23.41.MenuItem
23.41.1.new MenuItem()
23.41.2.Add action event handler to MenuItemAdd action event handler to MenuItem
23.41.3.Option Menu and RadioOption menuOption Menu and RadioOption menu
23.41.4.Owner Drawn MenuItemOwner Drawn MenuItem
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.