Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Class Form1
- Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
- Dim menu As New MenuStrip()
- For i As Integer = 0 To 2
- Dim item As New ToolStripMenuItem(String.Format("Menu {0}", i.ToString()))
- ' Modify item here
- item.Name = "myMenuItem"
- For j As Integer = 0 To 3
- ' For the sake of this demo set the item text to URL (you will need to get path to you file)
- Dim innerItem As New ToolStripMenuItem("https://www.google.co.uk/")
- ' Modify inner item here
- ' attach an event handler to each menu item
- AddHandler innerItem.Click, AddressOf ClickHandler
- item.DropDownItems.Add(innerItem)
- Next
- menu.Items.Add(item)
- Next
- Me.Controls.Add(menu)
- End Sub
- ' this is the event handler that handles all the menu click events
- Private Sub ClickHandler(sender As Object, e As EventArgs)
- 'demonstrates extracting the menu text
- System.Windows.Forms.MessageBox.Show(String.Format(" {0} {1}", DirectCast(sender, System.Windows.Forms.ToolStripMenuItem).OwnerItem.Text, DirectCast(sender, System.Windows.Forms.ToolStripMenuItem).Text))
- 'You can also launch files in the next line (has to be full path to the file tho)
- Process.Start(DirectCast(sender, System.Windows.Forms.ToolStripMenuItem).Text)
- End Sub
- End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement