new MenuItem : MenuItem « System.Windows.Forms « C# / C Sharp by API






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);
     }
}

   
  








Related examples in the same category

1.new MenuItem("&Open...",new EventHandler(MenuFileOpenOnClick),Shortcut.CtrlO)
2.extends MenuItem
3.MenuItem.Checked
4.MenuItem.Click
5.MenuItem.DrawItem
6.MenuItem.MeasureItem
7.MenuItem.MenuItems
8.MenuItem.OnSelect
9.MenuItem.Parent
10.MenuItem.Popup
11.MenuItem.Shortcut
12.MenuItem.Text