Changes

Jump to: navigation, search

Creating Top-Level Menus in Visual Basic

1,601 bytes added, 17:24, 24 July 2007
Programming Menu Items in Visual Basic
== Programming Menu Items in Visual Basic ==
 
No that we have designed a minu system in Visual Studio, the next step is to make the menu items do something when they are selected by a user. This is achieved using the event procedures of the individual menu options. We will demonstrate this using our example by wiring up the Exit menu option so that it closes the application, and by writing an event procedure for the ''Save on Exit'' menu option to change the checked status of the ''Checked'' menu item.
 
We will begin by writing a Visual Basic event procedure for when the Exit menu option is selected. In Visual Studio click on the ''File'' menu so that the menu drops down and double click on the ''Exit'' menu option. Visual Studio will subsequently display the ''Click'' event procedure for this menu item. All we need to do is add a Close() call to this procedure to exit the application:
 
<pre>
 
 
</pre>
 
Having made the appropriate change, press the '''F5''' key to build and run the application. Selecting the ''Exit'' option from the File menu should now cause the application to close. Restart the application and try the ''Ctrl+X'' keyboard shortcut to Exit the application.
 
The final step is to write some Visual Basic code to change the setting of the ''SaveOnExitMenu'' object such that selecting the option in the menu changes the checked status. To achieve this, double click on the ''Save On Exit'' in the ''Edit'' menu to display the ''Click'' event procedure for this object. Enter the following Visual Basic code to invert the current setting of the ''Checked'' property of the ''SaveOnExitMenu'' object:
 
<pre>
 
</pre>

Navigation menu