Create a Menu without using the IDE : Menu : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Menu »

 

Create a Menu without using the IDE








    
using  System;
using  System.Drawing;
using  System.ComponentModel;
using  System.Windows.Forms;

public  class  MenuCreationManually  :  System.Windows.Forms.Form
{
        void  ShowInfo(Object  Sender,EventArgs  e)
        {
                MenuItem  item=(MenuItem)Sender;
                switch(item.Text)
                {
                        case  "&Open":
                                Console.WriteLine("Open  a  file  from  disk");
                        break;
                        case  "&Save":
                                Console.WriteLine("Save  a  file  onto  disk");
                        break;
                        case  "E&xit":
                                Console.WriteLine("Exit  MenuApp");
                        break;
                }
        }

        public  MenuCreationManually()
        {
                this.MaximizeBox  =  true;
                this.FormBorderStyle  =  FormBorderStyle.Sizable;

                MainMenu  menu  =  new  MainMenu();

                

                MenuItem  filemenu  =  new  MenuItem();
                filemenu.Text  =  "&File";
                menu.MenuItems.Add(filemenu);

                        MenuItem  open  =  new  MenuItem();
                        open.Text  =  "&Open";
                        open.Select  +=  new  EventHandler(ShowInfo);
                        filemenu.MenuItems.Add(open);

                        MenuItem  save=  new  MenuItem();
                        save.Text  =  "&Save";
                        save.Select  +=  new  EventHandler(ShowInfo);
                        filemenu.MenuItems.Add(save);


                        MenuItem  exit=  new  MenuItem();
                        exit.Text  =  "E&xit";
                        exit.Select  +=  new  EventHandler(ShowInfo);
                        filemenu.MenuItems.Add(exit);
        
                this.Menu  =  menu;

                ContextMenu  cmenu  =  new  ContextMenu();
                cmenu.MenuItems.Add(new  MenuItem("&First"));
                cmenu.MenuItems.Add(new  MenuItem("&Second"));
                cmenu.MenuItems.Add(new  MenuItem("-"));
                cmenu.MenuItems.Add(new  MenuItem("&Third"));

                this.ContextMenu=cmenu;
        }

        static  void  Main()
        {
                Application.Run(new  MenuCreationManually());
        }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Menu