Using the Menu Designer
wpe7.jpg (11807 bytes)

bullet

Menus will always appear at the top of a form, no matter where you place the actual menu control

bulletVisual markers appear to the right and below to indicate the next available menu positions.
bulletbelow implies new menu items
bulletright implies new menu titles
bulletAdd File, Color, and Picture as menu titles.
bulletAdd Exit as the lone menu item for File
bulletAdd Red, Green, and Blue as menu items for Color
bulletAdd Visible as the lone menu item for Picture
bulletAdd access keys to each menu item - that the underscore (_) that is underneath one of the characters of the particular menu item or menu title
bulletPlace an & before the character you want to be the access key - eg. &File wil place the underscore under the F in File
bulletUsual placement of the & is in front of the first letter ... but if the first letter is already used by a different menu item, use a different letter!
bulletEach 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
bulletThe naming convention here is the menu title, followed by the menu item (if there is one), followed by Mnu
bulletChange 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

bullet

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());
}

bullet

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

bullet

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);

bullet

Add event handler code forpictureVisibleMnu that will:

bullet

reverse the value of the Checked property each time this menu item is selected (use setChecked() and getChecked() ).

bullet

add an actual pictureBox  to the form, and if Visible is selected, the picture becomes visible on the form, and if the picture is already visible, then make it invisible.

Download a solution here as a .zip file


Last edited by DrB on 18 February 2009