BugMan
Well-known member
Using VB.Net 2010 Express: I can't figure out how to detect the run time menu option that was selected from a Context Menu Strip. I've added the control to a form, added one option at design time and can trap that event, but not the menu option added at run time.
Surely this is simple, but escapes me!
Thanks in advance.
-----------------------------------------------------
Public Class Form1
'a Context Menu Strip was added to the form and at Design time,
'an item named "ToolStripMenuItem1" was added to the Context Menu.
' At Run time, I add other options depending on user settings.
'How are these Run time menu clicks detected?
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
'Here the design time menu option is detected
MsgBox("Design Time Menu Item 1 clicked")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here a menu option is added at run time...
' menu item displays correctly, but how do we detect that it was clicked?
ContextMenuStrip1.Items.Add("Run Time Menu Item")
End Sub
End Class
Surely this is simple, but escapes me!
Thanks in advance.
-----------------------------------------------------
Public Class Form1
'a Context Menu Strip was added to the form and at Design time,
'an item named "ToolStripMenuItem1" was added to the Context Menu.
' At Run time, I add other options depending on user settings.
'How are these Run time menu clicks detected?
Private Sub ToolStripMenuItem1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripMenuItem1.Click
'Here the design time menu option is detected
MsgBox("Design Time Menu Item 1 clicked")
End Sub
Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
'Here a menu option is added at run time...
' menu item displays correctly, but how do we detect that it was clicked?
ContextMenuStrip1.Items.Add("Run Time Menu Item")
End Sub
End Class