473,396 Members | 2,111 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

How to attach an event to an menu item

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
Nov 15 '05 #1
3 1276
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/
mi**@mag37.com
"Jane" <ja**@computerconcepts.co.nz> wrote in message
news:04****************************@phx.gbl...
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

Nov 15 '05 #2
Sorry, you said dynamically created (so double clicking won't work).
Anyway, the code below is more or less what you need. -mike

"Michael Mayer" <mi**@mag37.com> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
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/
mi**@mag37.com
"Jane" <ja**@computerconcepts.co.nz> wrote in message
news:04****************************@phx.gbl...
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


Nov 15 '05 #3
Hello Michael
Thanks for your reply. Your answer is very helpful. Now I
know what to do.
Cheers
Jane
-----Original Message-----
Sorry, you said dynamically created (so double clicking won't work).Anyway, the code below is more or less what you need. - mike
"Michael Mayer" <mi**@mag37.com> wrote in message
news:OC**************@TK2MSFTNGP10.phx.gbl...
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/
mi**@mag37.com
"Jane" <ja**@computerconcepts.co.nz> wrote in message
news:04****************************@phx.gbl...
> 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


.

Nov 15 '05 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: james | last post by:
Hello, I am having a little trouble creating an event handler for a context menu toolstripmenuitem. I've seen various tutorials and so on, but I keep getting a bit stuck! So far I have a second...
6
by: Joseph Geretz | last post by:
Writing an Outlook AddIn with C#. For the user interface within Outlook I'm adding matching pairs of Toolbar buttons and Menu items. All of the buttons and menu items are wired up to send events to...
13
by: pamelafluente | last post by:
Hello. I have written the following code (this code is on a control): Sub InitSomething() mSet(me.FindForm) End Sub Sub mSet(ByVal f As Control) For Each t As Control In f.Controls If...
12
by: Tom Bean | last post by:
I am trying to display a ContextMenuStrip when a user right-clicks on an item in a ListView and have encountered a something that seems strange to me. When the ListView is initially populated,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.