Javatpoint Logo
Javatpoint Logo

VB.NET Menu Control

A menu is used as a menu bar in the Windows form that contains a list of related commands, and it is implemented through MenuStrip Control. The Menu control is also known as the VB.NET MenuStrip Control. The menu items are created with ToolStripMenuItem Objects. Furthermore, the ToolStripDropDownMenu and ToolStripMenuItem objects enable full control over the structure, appearance, functionalities to create menu items, submenus, and drop-down menus in a VB.NET application.

Let's create a MenuBar by dragging a MenuStrip control from the toolbox and dropping it to the Windows form.

Step 1. Drag the MenuStrip control from the toolbox and drop it on to the Form.

VB.NET Menu Control

Step 2: Once the MenuStrip is added to the form, we can set various properties of the Menu by clicking on the MenuStrip control.

Properties of the MenuStrip Control

There are following properties of the VB.NET MenuStrip control.

Properties Description
CanOverflow The CanOverflow property is used to authenticate whether the control supports overflow functionality by setting values in the MenuStrip control.
Stretch The Stretch property is used to obtain a value that specifies whether the menustrip stretches from end to end in the MenuStrip control.
GripStyle The GripStyle property obtains or sets the visibility of the grip that uses the reposition of the menu strip control.
ShowItemToolTips It is used to obtain or set the value that determines if the ToolTips are displayed for the MenuStrip Control.
DefaultSize The DefaultSize property is used to get the default horizontal and vertical dimension of the MenuStrip in pixel when it is first created.

Methods of the MenuStrip Control

Method Description
CreateAccessibilityInstance() It is used to create a new accessibility instance for the MenuStrip Control.
ProcessCmdKey() The ProcessCmdKey method is used to process the command key in the MenuStrip Control.
CreateDefaultItem() The CreateDefaultItem method is used to create a ToolStripMenuItem with the specified text, image, and event handlers for the new MenuStrip.
OnMenuActivate() It is used to initiate the MenuActivate event in the MenuStrip control.
OnMenuDeactivate() It is used to start the MenuDeactivate event in the MenuStrip control.

Events of the MenuStrip Control

Events Description
MenuActivate When a user uses a menu bar control with a mouse or keyboard, a MenuActivate event occurs.
MenuDeactivate The MenuDeactivate event occurs when the MenuStrip control is deactivated in the Windows form.

Let's create a program to display the menu bar in the Windows form.

In this image, we have created the menu and sub-items of the menu bar in the form.

VB.NET Menu Control

Now, we write the Shortcut keys for the File subitems, such as New -> Ctrl + N, Open -> Ctrl + O, etc.

VB.NET Menu Control

After that, we can see the subitems of the Files with their Shortcut keys, as shown below.

VB.NET Menu Control

Menus.vb

Output:

VB.NET Menu Control

Click on the File menu that shows the multiple options related to files.

VB.NET Menu Control
Next TopicVB.NET MDI Form




Youtube For Videos Join Our Youtube Channel: Join Now

Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA