34,333
edits
Changes
→Creating a Top-Level Menu
Top-level menus (the type of menus that run across the top of forms) are created using the ''Menu Strip'' control. The first step in creating a menu, therefore, is to add a Menu Strip control to the form. With your Visual Studio project loaded, and the Form to which you wish to add the menu selected, double click on the ''Menu Strip'' control in the ''Menus and Toolbars'' section of the Visual Studio Toolbox. You will notice that the Menu Strip object is added to the panel beneath the form, and that a ''Type Here'' field appears at the top of the form as follows:
[[Image:gvisual_studio_new_menu.jpg]]
Use the ''Properties'' panel to change the name of the ''Menu Strip'' object to ''mainMenu''. Click in the ''Type Here'' field at the top of the form and enter ''&File''. This as the effect of creating a menu item object labeled "File". The ampersand (&) is added to instruct Visual Basic to use the 'F' at the beginning of the file as the accelerator key for this menu item. As such, pressing Alt+F when the application is running will be equivalent to clicking on the menu item with the mouse pointer. The location of the ampersand in the menu item ''Text'' property dictates the accelerator key. For example ''H&elp'' will declare 'e' as the accelerator for this particular men item. Windows indicates the accelerator for a menu item by underlining the letter (as you will see by the underlined 'F' on your File menu item).