8.5 Creating and Attaching Menus to a Windows Form

 <  Day Day Up  >  

8.5 Creating and Attaching Menus to a Windows Form

You want to create a main menu for your Windows Form.


Technique

You can create a menu and its associated menu items by dragging and dropping a MainMenu control from the form designer toolbox onto the form that uses the menu. The menu editor appears directly in your form, allowing you to perform an in-place edit of the menu. To create a menu item, type text in the Type Here locations of the menu editor. You can create pop-up menus by editing the menu items that pop up in the editor to the left or right side of an already existing menu item. To insert a new menu item between two existing menu items, press the Insert key on the keyboard. You can also insert a menu separator by right-clicking on the menu and selecting the Insert Separator menu option.

As a shortcut, you can directly edit the menu item variable names within the menu editor by right-clicking on the menu and selecting the Edit Names menu item. The variables that represent the generated private member variables for each menu item then appear, allowing you to change those values, as shown in Figure 8.1.

Figure 8.1. Edit the associated menu item variable names by entering the Edit Names mode of the menu editor.

graphics/08fig01.gif

Comments

Menus allow you to place a large amount of application functionality using a minimal amount of screen real estate. Creating a menu within the forms designer is unique because rather than use the property browser as is custom with most other controls, you alter the appearance of the menu using a WYSIWYG menu editor. Using the form designer menu editor, you can create any number of top-level menu items, each with their own associated submenu items and separators. Each one of those submenu items can also contain any number of pop-up cascading menu items themselves .

To create an event handler for a specific menu item, select the menu item in the menu editor and double-click it to add the Click event handler. Another event that you can handle which might prove useful is the Popup event. By creating an event handler for this event, you can dynamically alter the contents of the menu before it appears to the user . For instance, the Popup handler can check whether any text is selected within a TextBox control. If no text is selected, you can disable any text operations such as Cut , Copy , or Paste .

 <  Day Day Up  >  


Microsoft Visual C# .Net 2003
Microsoft Visual C *. NET 2003 development skills Daquan
ISBN: 7508427505
EAN: 2147483647
Year: 2003
Pages: 440

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net