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.
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.
||The CanOverflow property is used to authenticate whether the control supports overflow functionality by setting values in the MenuStrip control.
||The Stretch property is used to obtain a value that specifies whether the menustrip stretches from end to end in the MenuStrip control.
||The GripStyle property obtains or sets the visibility of the grip that uses the reposition of the menu strip control.
||It is used to obtain or set the value that determines if the ToolTips are displayed for the MenuStrip Control.
||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
||It is used to create a new accessibility instance for the MenuStrip Control.
||The ProcessCmdKey method is used to process the command key in the MenuStrip Control.
||The CreateDefaultItem method is used to create a ToolStripMenuItem with the specified text, image, and event handlers for the new MenuStrip.
||It is used to initiate the MenuActivate event in the MenuStrip control.
||It is used to start the MenuDeactivate event in the MenuStrip control.
Events of the MenuStrip Control
||When a user uses a menu bar control with a mouse or keyboard, a MenuActivate event occurs.
||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.
Now, we write the Shortcut keys for the File subitems, such as New -> Ctrl + N, Open -> Ctrl + O, etc.
After that, we can see the subitems of the Files with their Shortcut keys, as shown below.
Click on the File menu that shows the multiple options related to files.