spacer
Yehuda Shiran September 10, 2002
Implementing Windows Form's Menus
Tips: September 2002

Yehuda Shiran, Ph.D.
Doc JavaScript

Developer News
Microsoft Shows Off Silverlight 4, IE9 Plans
Metasploit Expands Vulnerability Test Framework
HyperCard Reborn?

Continuing our example from yesterday, we first initialize menuSave, then menuFile, and finally menuMain. Here is the definition of menuSave:

  menuSave = new System.Windows.Forms.MenuItem();
  menuSave.add_Click(menuSave_Clicked);
  menuSave.Text = "Save";
  menuSave.ShowShortcut = true;
  menuSave.Shortcut = "CtrlS";
The event handler of a Click event is menuSave_Clicked. We just pop up a message box as a response to the Click event:

  private function menuSave_Clicked(o : Object, e : EventArgs) {
    MessageBox.Show("We should save the file now");
  }
We continue with the initialization of menuFile. We can now add the previously-initialized menuSave:

  menuFile = new System.Windows.Forms.MenuItem();
  menuFile.MenuItems.Add(menuSave);
  menuFile.Text = "File";
  menuFile.ShowShortcut = false;
We finish the menu creation by initializing the top menu bar and adding menuFile to it:

  menuMain = new System.Windows.Forms.MainMenu();
  menuMain.MenuItems.Add(menuFile);
The package name is MenuPkg and the class name is MenuCls. We pop up the windows form by calling Application.Run():

  Application.Run(new MenuPkg.MenuCls());
You should get the following window:

To learn more about JScript .NET and ASP.NET, go to Column 117, JScript .NET, Part XI: Creating Windows Forms.


People who read this tip also read these tips:

Look for similar tips by subject:

internet.commediabistro.comJusttechjobs.comGraphics.com

Search:

WebMediaBrands Corporate Info

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | Shopping | E-mail Offers | Freelance Jobs

webref The latest from WebReference.com Browse >
Rolling Out Your Own HTML Application Version Control · HTML 5: Client-side Storage · Working with Ajax Server Extensions
Sitemap · Experts · Tools · Services · Email a Colleague · Contact FREE Newsletters 
 The latest from internet.com
Wi-Fi Product Watch, November 2009 · Chip Market Recovering From '08 Collapse · Low-Cost Tools to Kickstart Your New Business