1: // project created on 7/26/2003 at 11:28 AM
     2: using System;
     3: using System.Windows.Forms;
     4: using Crownwood.Magic.Menus;
     5: 
     6: namespace MyFormProject 
     7: {
     8:         class MainForm : System.Windows.Forms.Form
     9:         {
    10:                 private Crownwood.Magic.Menus.MenuControl mclMain;
    11: 
    12:                 public MainForm()
    13:                 {
    14:                         InitializeComponent();
    15:                         BuildMainMenu();
    16:                 }
    17:         
    18:                 // THIS METHOD IS MAINTAINED BY THE FORM DESIGNER
    19:                 // DO NOT EDIT IT MANUALLY! YOUR CHANGES ARE LIKELY TO BE LOST
    20:                 void InitializeComponent() {
    21:                         this.SuspendLayout();
    22:                         // 
    23:                         // MainForm
    24:                         // 
    25:                         this.ClientSize = new System.Drawing.Size(230, 100);
    26:                         this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.Fixed3D;
    27:                         this.Text = "Magic Menu Example";
    28:                         this.ResumeLayout(false);
    29:                 }
    30:                 
    31:                 
    32:                 /// <summary>
    33:                 /// Build the Main menu and add it to the main Form
    34:                 /// </summary>
    35:                 private void BuildMainMenu()
    36:                 {
    37:                         //
    38:                         //Create the main menu
    39:                         //
    40:                         mclMain = new MenuControl();
    41:                         
    42:                         //
    43:                         //Create the File menu and add to Main
    44:                         //
    45:                         MenuCommand mcFile = new MenuCommand("&File");
    46:                         mcFile.Description = "File related commands";
    47:                         //
    48:                         //  Create the Open menu item
    49:                         //
    50:                         MenuCommand mcFile_Open = new MenuCommand("&Open",
    51:                                                                   Shortcut.CtrlO,
    52:                                                                   new EventHandler(mcFile_Open_Click)
    53:                                                                   );
    54:                         mcFile_Open.Description = "Open a file.";
    55:                         //
    56:                         //      Create the Save menu item
    57:                         //
    58:                         MenuCommand mcFile_Save = new MenuCommand("&Save");
    59:                         mcFile_Save.Shortcut = Shortcut.CtrlS;
    60:                         mcFile_Save.Click += new EventHandler(mcFile_Save_Click);
    61:                         mcFile_Save.Description = "Save the selected file.";
    62: 
    63:                         //
    64:                         //      Add Open and Save to the File menu
    65:                         //
    66:                         mcFile.MenuCommands.AddRange(new MenuCommand[]{mcFile_Open,
    67:                                                      mcFile_Save
    68:                                                      });
    69:                         //
    70:                         //      Add File to the Main menu
    71:                         //
    72:                         mclMain.MenuCommands.Add(mcFile);
    73:                         
    74:                         //
    75:                         //      Add the Main menu to the form.
    76:                         //
    77:                         this.Controls.Add(mclMain);
    78:                 }
    79: 
    80:                 /// <summary>
    81:                 /// Click event handler for the File_Open menu item
    82:                 /// </summary>
    83:                 /// <param name="sender">The sender of the Event</param>
    84:                 /// <param name="e">The arguments for the Event</param>
    85:                 private void mcFile_Open_Click(object sender, EventArgs e)
    86:                 {
    87:                         MessageBox.Show("File_Open");
    88:                 }
    89: 
    90:                 /// <summary>
    91:                 /// Click event handler for the File_Save menu item
    92:                 /// </summary>
    93:                 /// <param name="sender">The sender of the Event</param>
    94:                 /// <param name="e">The arguments for the Event</param>
    95:                 private void mcFile_Save_Click(object sender, EventArgs e)
    96:                 {
    97:                         MessageBox.Show("File_Save");
    98:                 }
    99: 
   100:                 [STAThread]
   101:                 public static void Main(string[] args)
   102:                 {
   103:                         Application.Run(new MainForm());
   104:                 }
   105:         }                       
   106: }
   107: