Using the Menu Designer

Menus will always appear at the top of a form, no matter where you place the actual menu control | |||||||
Visual markers appear to the right and below to indicate the next available menu
positions.
| |||||||
Add File, Color, and Picture as menu titles.
| |||||||
Add access keys to each menu item - that the underscore (_) that is underneath
one of the characters of the particular menu item or menu title
| |||||||
| Each menu item and menu title corresponds to a unique control being added to your form.
The default name for these are menuItem plus a number (eg. menuItem1,
menuItem2, etc.). These names tell you nothing! So you should change the
name propoerty of each menu item to something like -- |
| Menu Text Property | Menu Name Property |
| &File | fileMnu |
| E&xit | fileExitMnu |
| &Color | colorMnu |
| &Red | colorRedMnu |
| &Green | colorGreenMnu |
| &Blue | colorBlueMnu |
| &Picture | pictureMnu |
| &Visible | pictureVisibleMnu |
| The naming convention here is the menu title, followed by the menu item (if there is one), followed by Mnu | |
| Change the checked propoerty for pictureVisibleMnu to true. This will put a small check mark next to the menu item when you run the program. |
Event Handlers
Double-click on a menu item ... skeleton event handler code will be generated. For fileExitMnu, you need to add code so that the application ends -- |
private void fileExitMnu_click(Object source, Event e)
{
Application.exit());
}
Add menu shortcuts to the controls using the Shortcut property. Shortcuts are function key combinations that work like a mouse click on the menu item, e.g. Ctrl-+R . Add shortcuts Ctrl+R for colorRedMnu, Ctrl-G for colorGreenMnu, and Ctrl+B for colorBlueMnu by right clicking on the control and selecting a combination or modifying the shortcut property in the properties table for the control. |
Finalizing the Program
Add event handler code for the color selections so that the background of the form is set to the color selected -- for red -> setBackColor(Color.RED); | |||||
Add event handler code forpictureVisibleMnu that will:
|
Download a solution here as a .zip file
![]()
Last edited by DrB
on 18 February 2009