VB.NET MenuStrip Control.
The VB.NET Windows MenuStrip control provides an application menu system. The menustrip works with both Single document interfaces SDI and Multiple document interfaces MDI. With MDI applications the MenuStrip can be configured to merge with the main form for better navigation.
Namespace: System::Windows::Forms
System.Windows.Forms (in system.windows.forms.dll)
Creating an new VB.NET Windows forms MenuStrip.
Dim menustrip As New MenuStrip
Assigning a new location for the VB.NET Windows Forms MenuStrip.
menustrip.Location = New Point(0, 0)
Assigning a size value to the VB.NET MenuStrip.
menustrip.Size = New Size(Me.Width, 24)
Now we need to add menuitems to the menustrip control. The items I am speaking about are the dropdown menus, File, Edit, Windows etc, and the clickable button items within the menus, Open, Save, SaveAS etc.
Adding the first menu item - MenuStripItem.
Dim menuitem1 As New ToolStripMenuItem
Assigning a text value to the MenuStripItem
menuitem1.Text = "File"
Adding an image to the MenuStripItem.
menuitem1.Image = Image.FromFile("e:\file.png")
Now we add the first MenuStripItem to the MenuStrip itself.
menustrip.Items.Add(menuitem1)
Next we are going to add a second MenuStripItem but we are going to add it to the first MenuStripItem as a dropdown item.
Dim menuitem2 As New ToolStripMenuItem
menuitem2.Text = "Exit"
Adding menuitem2 as a DropDown Menu item.
menuitem1.DropDownItems.Add(menuitem2)
Adding a VB.NET MenuStrip control to the form.
Me.Controls.Add(menustrip)
Assign the MainMenuStrip to the form.
Me.MainMenuStrip = menustrip
Creating a Click Event for the VB.NET MenuStripItem control.
AddHandler menuitem2.Click, AddressOf menuitem2_click
Responding to the VB.NET MenuStripItem Click event.
Private Sub menuitem2_click(ByVal sender As Object, ByVal e As EventArgs)
MessageBox.Show("Menuitem Clicked")
End Sub
|
|