Set MenuItem ShortCut : MenuItem : GUI Windows Form C# Source Code


Custom Search

C# Source Code » GUI Windows Form » MenuItem »

 

Set MenuItem ShortCut








    
 

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

 
    
   
  
   







HTML code for linking to this page:

Follow Navioo On Twitter

C# Source Code

 Navioo GUI Windows Form
» MenuItem