How to attach an event to an menu item

  • Thread starter Thread starter Jane
  • Start date Start date
J

Jane

Hi
I am using a Visual Studio .Net 7.0 trail version in
Windows XP.
I've dynamically created some menu items. Now I want to
attach an event to these items, what should I do?
Thanks
Jane
 
You can double click on those menu items, and the IDE should insert code
somewhat similar to the following:

(in the Designer Generated Code Section)

this.menuItem1.Clicked += new System.EventHandler(menuItem1_Clicked);

(then at the bottom of the .cs file)

void menuItem1_Clicked (object sender, EventArgs e)
{
}

Just write code in that method to do what you'd have happen on the "click"
event.
(I just typed all of the above off the top of my head, there may very well
be some typos)

HTH,
Mike Mayer
http://www.mag37.com/csharp/
(e-mail address removed)
 
Sorry, you said dynamically created (so double clicking won't work).
Anyway, the code below is more or less what you need. -mike
 
Hello Michael
Thanks for your reply. Your answer is very helpful. Now I
know what to do.
Cheers
Jane
 
Back
Top