- VB.Net Basic Tutorial
- VB.Net - Home
- VB.Net - Overview
- VB.Net - Environment Setup
- VB.Net - Program Structure
- VB.Net - Basic Syntax
- VB.Net - Data Types
- VB.Net - Variables
- VB.Net - Constants
- VB.Net - Modifiers
- VB.Net - Statements
- VB.Net - Directives
- VB.Net - Operators
- VB.Net - Decision Making
- VB.Net - Loops
- VB.Net - Strings
- VB.Net - Date & Time
- VB.Net - Arrays
- VB.Net - Collections
- VB.Net - Functions
- VB.Net - Subs
- VB.Net - Classes & Objects
- VB.Net - Exception Handling
- VB.Net - File Handling
- VB.Net - Basic Controls
- VB.Net - Dialog Boxes
- VB.Net - Advanced Forms
- VB.Net - Event Handling
- VB.Net Advanced Tutorial
- VB.Net - Regular Expressions
- VB.Net - Database Access
- VB.Net - Excel Sheet
- VB.Net - Send Email
- VB.Net - XML Processing
- VB.Net - Web Programming
- VB.Net Useful Resources
- VB.Net - Quick Guide
- VB.Net - Useful Resources
- VB.Net - Discussion
VB.Net - MenuStrip Control
The MenuStrip control represents the container for the menu structure.
The MenuStrip control works as the top-level container for the menu structure. The ToolStripMenuItem class and the ToolStripDropDownMenu class provide the functionalities to create menu items, sub menus and drop-down menus.
The following diagram shows adding a MenuStrip control on the form −
Properties of the MenuStrip Control
The following are some of the commonly used properties of the MenuStrip control −
Sr.No. | Property & Description |
---|---|
1 | CanOverflow Gets or sets a value indicating whether the MenuStrip supports overflow functionality. |
2 | GripStyle Gets or sets the visibility of the grip used to reposition the control. |
3 | MdiWindowListItem Gets or sets the ToolStripMenuItem that is used to display a list of Multiple-document interface (MDI) child forms. |
4 | ShowItemToolTips Gets or sets a value indicating whether ToolTips are shown for the MenuStrip. |
5 | Stretch Gets or sets a value indicating whether the MenuStrip stretches from end to end in its container. |
Events of the MenuStrip Control
The following are some of the commonly used events of the MenuStrip control −
Sr.No. | Event & Description |
---|---|
1 | MenuActivate Occurs when the user accesses the menu with the keyboard or mouse. |
2 | MenuDeactivate Occurs when the MenuStrip is deactivated. |
Example
In this example, let us add menu and sub-menu items.
Take the following steps −
Drag and drop or double click on a MenuStrip control, to add it to the form.
Click the Type Here text to open a text box and enter the names of the menu items or sub-menu items you want. When you add a sub-menu, another text box with 'Type Here' text opens below it.
Complete the menu structure shown in the diagram above.
Add a sub menu Exit under the File menu.
-
Double-Click the Exit menu created and add the following code to the Click event of ExitToolStripMenuItem −
Private Sub ExitToolStripMenuItem_Click(sender As Object, e As EventArgs) _ Handles ExitToolStripMenuItem.Click End End Sub
When the above code is executed and run using Start button available at the Microsoft Visual Studio tool bar, it will show the following window:
Click on the File -> Exit to exit from the application −