all groups > c# > august 2003 >
You're in the

c#

group:

How to attach an event to an menu item


How to attach an event to an menu item Jane
8/31/2003 8:37:17 PM
c#:
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
Re: How to attach an event to an menu item Michael Mayer
8/31/2003 11:47:23 PM
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/
mike@mag37.com


[quoted text, click to view]

Re: How to attach an event to an menu item Michael Mayer
9/1/2003 2:06:13 AM
Sorry, you said dynamically created (so double clicking won't work).
Anyway, the code below is more or less what you need. -mike

[quoted text, click to view]

Re: How to attach an event to a menu item Jane
9/1/2003 1:58:48 PM
Hello Michael
Thanks for your reply. Your answer is very helpful. Now I
know what to do.
Cheers
Jane

[quoted text, click to view]
AddThis Social Bookmark Button