Menu Control in VB.Net

A menu, an integral component of a graphical user interface, is typically positioned on the menu bar and serves as a gateway to a collection of interconnected commands. It provides users with a list of options and actions that are grouped together based on their related functionality.

The MainMenu control serves as a container for structuring the menu system within a form. This control enables the creation and organization of menus by utilizing MenuItem objects, which represent the individual components or parts of a menu.

MainMenu object

To incorporate a menu into a form, you can create a MainMenu object by employing the MainMenu control. This control acts as the foundation for building the menu structure within the form, allowing you to define the hierarchical arrangement and association of menus and their respective menu items.

vb.net-menu-control.jpg

To illustrate the process of adding a MainMenu object to a form, the provided picture demonstrates how to drag and drop a Menustrip Object onto the form. This visual representation emphasizes the straightforward nature of incorporating the menu functionality within your form's design.

After drag the Menustrip on your form you can directly create the menu items by type a value into the "Type Here" box on the menubar part of your form. From the following picture you can understand how to create each menu items on mainmenu Object.

vb.net-menubar.jpg

If you need a separator bar , right click on your menu then go to insert->Separator.

vb.net-menu-seperator.jpg

After creating the Menu on the form , you have to double click on each menu item and write the programs there depends on your requirements. The following Vb.Net program shows how to show a messagebox when clicking a menu item.

Full Source VB.NET
Public Class Form1 Private Sub MenuItem1ToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MenuItem1ToolStripMenuItem.Click MsgBox("You are selected MenuItem_1") End Sub End Class

Conclusion

By utilizing the capabilities of the MainMenu control and MenuItem objects, you can seamlessly construct a comprehensive and user-friendly menu system that provides clear navigation and access to various commands and functionalities within your VB.Net application.