Changes

Creating Top-Level Menus in Visual Basic

76 bytes added, 17:39, 24 July 2007
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:visual_studio_new_menu.jpg| Visual Basic Add New Menu]]
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).
Once the File menu item has been added, Visual Studio will create both a drop down menu and a field to add another menu item as follows:
[[Image:Examplvisual_basic_drop_down_menu.jpg| Visual basic 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 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: