Changes

Creating Context Menus in Visual Basic

23 bytes added, 20:13, 25 July 2007
Adding Context Menus to a Visual Basic Form
The purpose of this example is to create a context menu on form which will contain options to hide and show the ''MyTextBox''' object. From the Visual Studio Toolbox, double click on the ''ContextMenuStrip'' object. The object will be added to the form. You will notice, however, that since the menu is not located at any specific position in the form, it is located in the panel beneath the form. To display the menu in the form, or edit properties of the object, simply click on this instance of the object. With the object selected, change the name to ''TextBoxMenu'' by changing the ''Name'' property in the Properties panel. You will notice also, that a representation of the context appears in the form area:
[[Image:Examplvisual_basic_new_context_menu.jpg]]
Add items to the menu simply by typing in the ''Type Here'' fields. Each time you enter a new item a new ''Type Here'' field will appear. To add an item other than a menu option, click on the small down arrow which appears in the text box. It is possible to add ComboBoxes, Separators, TextBoxes and MenuItems to a context menu. With the exception of separators and MenuItems, these items should not be placed in menus because they violate the rules of good GUI design.