VB icon

Create menus without using mainmenu control on form

Email
Submitted on: 1/1/2015 2:12:00 AM
By: markbm (from psc cd)  
Level: Beginner
User Rating: By 5 Users
Compatibility: VB.NET
Views: 1349
 
     This example will create simple menu on form without using mainmenu control.
 
code:
Can't Copy and Paste this?
Click here for a copy-and-paste friendly version of this code!
				
//**************************************
// Name: Create menus without using mainmenu control on form
// Description:This example will create simple menu on form without using mainmenu control.
// By: markbm (from psc cd)
//**************************************

' Create an empty MainMenu.
 Dim mainMenu1 As New MainMenu()
 Dim menuItem1 As New MenuItem("&File")
 Dim menuItem2 As New MenuItem()
 Dim menuitem3 As New MenuItem()
 Dim menuItem5 As New MenuItem("&Help")
 Dim menuitem6 As New MenuItem()
 ' Set the caption for the first submenu.
 menuItem2.Text = "&Open"
 menuitem3.Text = "E&xit"
 ' set the caption for second submenu
 menuitem6.Text = "&About"
 ' Add menuItem2 and menuItem3 to menuItem1's list of menu items.
 menuItem1.MenuItems.Add(menuItem2)
 menuItem1.MenuItems.Add(menuitem3)
 ' Add menuItem6 to menuItem5's list of menu items.
 menuItem5.MenuItems.Add(menuitem6)
 ' Add two MenuItem objects to the MainMenu for displaying.
 mainMenu1.MenuItems.Add(menuItem1)
 mainMenu1.MenuItems.Add(menuItem5)
 AddHandler menuItem2.Click, AddressOf Me.Item1_Click 'handles the menuitem2 click
 AddHandler menuitem3.Click, AddressOf Me.Item2_Click 'handles the menuitem3 click
 AddHandler menuitem6.Click, AddressOf Me.Item3_Click 'handles the menuitem6 click
 Me.Menu = mainMenu1
 End Sub
 Private Sub Item1_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 MessageBox.Show("You clicked the open menu.")
 End Sub
 Private Sub Item2_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 MessageBox.Show("You clicked the exit menu.")
 End
 End Sub
 Private Sub Item3_Click(ByVal sender As Object, ByVal e As System.EventArgs)
 MessageBox.Show("You clicked the About menu.")
 End Sub


Other 1 submission(s) by this author

 


Report Bad Submission
Use this form to tell us if this entry should be deleted (i.e contains no code, is a virus, etc.).
This submission should be removed because:

Your Vote

What do you think of this code (in the Beginner category)?
(The code with your highest vote will win this month's coding contest!)
Excellent  Good  Average  Below Average  Poor (See voting log ...)
 

Other User Comments


 There are no comments on this submission.
 

Add Your Feedback
Your feedback will be posted below and an email sent to the author. Please remember that the author was kind enough to share this with you, so any criticisms must be stated politely, or they will be deleted. (For feedback not related to this particular code, please click here instead.)
 

To post feedback, first please login.