Handling events for code-created contextmenuitems

mickn66

Well-known member
Joined
Nov 2, 2002
Messages
53
Ok, heres the situation. My program creates in code a context menu called mnuContextMenu, to which I add menuitems with code like mnuContextMenu.MenuItems.Add(txt.Text).

I want all of the items in this context menu to do the same things when clicked, namely copy the text of the menuitem to the clipboard. I know how to copy things to the clipboard, what I dont know how to do is create an event handler for these programmatically-added menuItems. Please help! Thanks.
 
you can try someing like this:
Code:
Me.MenuItem2.Index = 0
Me.MenuItem2.MenuItems.AddRange(New System.Windows.Forms.MenuItem() )
Me.MenuItem2.Text = "Enter Text"
i dont know if it will work but try that
 
Code:
AddHandler object.Event, AddressOf handlersub
Where handlersub is the sub that will handle the event, it must also accept arguments that correspond to the event.
 
Back
Top