473,503 Members | 1,654 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Passing parameter to MenuItem.Click handler

I would like to have a number of items on my C# menu and I would like them
all to invoke the same handler, but with each passing different data (say
some integer) that will be based on which menu item was clicked.

I can derive a class from EventArgs, but how do I associate a new instance
of this derived class with a particular menu item click. (the result I want
would be directly analogous to the MouseXXX events that provide dynamic
information like cursor position, etc.

I have seen a couple of discussion threads using
Delegate.CreateDelegate(), but they don't seem to do quite what I want.

Thanks in advance.
Valerie Hough

Thanks in advance.
Nov 16 '05 #1
1 2753
On Tue, 29 Jun 2004 19:55:33 -0400, "Valerie Hough"
<sa***@pcTrans.com> wrote:
I would like to have a number of items on my C# menu and I would like them
all to invoke the same handler, but with each passing different data (say
some integer) that will be based on which menu item was clicked.
You don't need to extend EventArgs to do that, just examine the
sender. It should be the MenuItem object that was clicked on.
I can derive a class from EventArgs, but how do I associate a new instance
of this derived class with a particular menu item click. (the result I want
would be directly analogous to the MouseXXX events that provide dynamic
information like cursor position, etc.


You can't do this with a standard menu item. You would have to derive
your own class and override OnClick to supply your EventArgs instance.
--
http://www.kynosarges.de
Nov 16 '05 #2

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

Similar topics

3
1804
by: serge calderara | last post by:
Dear all, I have a class named for Instance "MyClass" which populate trough an interface a context menu object to the main application. The click event on any of the context menu itemm will be...
4
5116
by: Norvin Laudon | last post by:
Hi, I have a context menu, which is used for each of 6 labels on my form. That is, right-clicking any of the labels will bring up the same context menu. Once the user clicks the menu, the...
6
6207
by: Claus Holm | last post by:
I'm trying to enable a menuitem in the parent form from a mdichild. Rather than making the menuitems public, I'd go for a public method in the parent form to do the change, but when I call the...
2
1590
by: M Shafaat | last post by:
Hi, I want to develop an application with menus. I want to make only one event handler method which handles a whole group of menu items by firstly identifying which MenuItem sends the click event...
5
6559
by: Vinay | last post by:
Hi, I have created a Context Menu class (CMenu) with relevant items. Based on a selected Item, I am taking a separate action. The following code is working fine. CMenu(sOption as string)...
7
9541
by: Richard Grant | last post by:
Hi. In c/C++ i can pass the address of a subroutine to another subroutine as an actual parameter How do I do that in VB .NET What should be the syntax for a parameter to receive the address of a...
4
1592
by: Robin Tucker | last post by:
Hi there, I need to add a click handler to a derived menu item class. I am using the same handler to handle all of the items in the given menu, but need to derive a new menu item class in order...
2
2306
by: David A. Osborn | last post by:
I need to pass the address of a function to the contructor of a class when I create an instance of it so that in the new instance I can dynamically hookup a handler by doing the following: ...
9
2097
by: Sharon | last post by:
I have a Forms.ContextMenu with some Forms.MenuItem that has EventHandler for the Click event. The event handler function has the following signature: private void OnMenuItemClick(object...
0
7198
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,...
1
6979
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
7449
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
5570
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,...
0
4666
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and...
0
3149
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
0
1498
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated ...
1
730
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
373
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence...

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.