• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 840
  • Last Modified:

WinForms C#: How do I associate event with a ToolStripMenuItem ?

I can no longer use the Designer to create and populate my ToolStripMenuItems, because my context menus need to be 100% dynamically created.  So I need to do them in code.

How can I associate an existing event handler with a ToolStripMenuItem?



Thanks!
0
newbieweb
Asked:
newbieweb
1 Solution
 
MisbahCommented:
for each menu item you add, set the event handler like this:

menuItem.Click +=new EventHandler(menuItem_Click);

//and then put the code you want to execute in the menuItem_Click method
private void menuItem_Click(object sender, EventArgs e)
        {
          // code here will be executed after clicking on menu item
        }
0
 
newbiewebAuthor Commented:
Thanks!
0

Featured Post

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now