Changes

Jump to: navigation, search

Creating Top-Level Menus in C Sharp

9 bytes added, 20:00, 1 April 2009
no edit summary
[[Image:c_sharp_drop_down_menu.jpg|C# New Menu Item]]
Click on the ''Type Here'' field and type ''&Open File...''. When you have entered this text Visual Studio will add another ''Type Here'' field beneath the "Open File" entry. Click in this field and enter ''&Read File...''. Once again, Visual Studio provide provides the opportunity to add another item. This time, however, we are going to add a different type of item to the menu. As you move the mouse pointer over the ''Type Here'' field, the field will highlight and a down arrow will appear to the right of the ''Type Here'' text. Clicking on this arrow drops down a menu of items to add to the menu:
[[Image:c_sharp_menu_item_types.jpg| Visual Studio Menu Item Types]]
[[Image:visual_basic_menu_checked.jpg]]
To created create a ''Checked'' item in the menu enter ''Save on Exit'' in the ''Type Here'' field and then right click on the item to display the popup menu. From the menu, select ''Checked''. The menu item will now be displayed with a check mark next to it. In the property panel for the checked menu item, change the ''Name'' property to ''SaveOnExitMenu''.
The menu is now ready to be tested. Press the '''F5''' key to build and run the application. When it appears, click on the File and Edit menus to confirm that they appear as you intended.
== Deleting and Moving Menu Items ==
To delete a menu item in Visual Studio, simply right click on the item and select ''Delete'' from the popup menu. To move an item within the same menu, click and drag the item to the new position by holding down the mouse button. Release the button when the mouse pointer reaches the new location. To move an item from one menu to another, first right click over the menu item, then select ''Cut'' from the popup menu. Next, click on the new menu to which you wish to move the item and, with the mouse position positioned on the menu item you wish to appear ''below'' the new item, right click and select ''Paste''.
== Assigning Keyboard Shortcuts to Menu Items ==
It is conventional to allow menu items to be selected using the keyboard using what are know known as ''keyboard shortcuts''. These are key sequences that typically involve pressing a key whilst holding down the ''Ctrl'', ''Alt'' or ''Shift'' key.
Keyboard shortcuts are defined by setting the ''ShortcutKeys'' property of a menu item object. For example, to configure the Exit menu item to use ''Ctrl-X'' , select the menu item and click in the value field of the ''ShortcutKeys'' property in the Visual Studio Properties panel. A panel will appear providing the option to select ''Ctrl'', ''Shift'' or ''Alt'' and also the key to be pressed in conjunction. Use this panel to configure the ''Ctrl+X'' key sequence for this menu item.
== Programming Menu Items in C# ==

Navigation menu