How can you add a click event to dynamically created menu item?
I thought I could do something like
Loop through all the items in the Menu1.DropDownItems then create a mousedown even on the item and execute an action based off that.
I’m new to VB and was wondering what logic to use. Will that even work? How will the events be saved through the life of the application?
You will have to have a method that fits the event’s signature. Then, when creating the MenuItem, you can add a handler to the event:
You cannot create an event in a class that you don’t have access to. The only option would be to derive from it, but this works only in some cases. In case of the MenuItem, this is not even necessary, because it already provides a Click event. You just have to add a handler for it. The handler is saved in the item’s event, which maintains a kind of list of handlers.