Private Sub mnuHello_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mnuHello.Click
strMenuText = mnuHello.text
End Sub
' your method would look something like this
Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
Dim mnuItem As MenuItem = DirectCast(sender, MenuItem)
MessageBox.Show(mnuItem.Text)
End Sub
'
' and just so you know, it would be attached to the event like so
AddHandler MenuItem2.Click, AddressOf MenuItem2_Click
Cags said:techmanbds' suggestion would work, but would require coding every single menu item individually at design time, which isn't possible if it's a dynamically created item. A more generic method could be used by attaching an event handler that simply casts the sender object then gets the text.
Visual Basic:' your method would look something like this Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim mnuItem As MenuItem = DirectCast(sender, MenuItem) MessageBox.Show(mnuItem.Text) End Sub ' ' and just so you know, it would be attached to the event like so AddHandler MenuItem2.Click, AddressOf MenuItem2_Click
Private Sub RelocatableModularBuildingsToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles RelocatableModularBuildingsToolStripMenuItem.Click
WebSearch = sender.ToString
End Sub
Cags said:techmanbds' suggestion would work, but would require coding every single menu item individually at design time, which isn't possible if it's a dynamically created item. A more generic method could be used by attaching an event handler that simply casts the sender object then gets the text.
Visual Basic:' your method would look something like this Private Sub MenuItem2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Dim mnuItem As MenuItem = DirectCast(sender, MenuItem) MessageBox.Show(mnuItem.Text) End Sub ' ' and just so you know, it would be attached to the event like so AddHandler MenuItem2.Click, AddressOf MenuItem2_Click
Private Sub AnyToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) _
[I] Handles RelocatableModularBuildingsToolStripMenuItem.Click,
SomeOtherToolStripItem.Click,
YetAnotherToolStripItem.Click,
OneMoreToolStripItem.Click[/I]
WebSearch = DirectCast(sender, ToolStripItem).Text
End Sub