473,657 Members | 3,021 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.Create Delegate(), but they don't seem to do quite what I want.

Thanks in advance.
Valerie Hough

Thanks in advance.
Nov 16 '05 #1
1 2762
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
1816
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 proceed in the myClass event handler. Actally default event handle has two parameters: Sender and e Actually the context menu is shown in my main application
4
5122
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 clicked MenuItem fires an event: menuItem1_Click(object sender, System.EventArgs e) How can tell which of the 6 labels the menu is being clicked over?
6
6219
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 method from the mdichild, I get this error: C:\MyProjects\Visual Studio Projects\Tournament\Forms\frmLogin.cs(69): The name 'test' does not exist in the class or namespace 'Tournament.frmLogin' frmLogin is the mdichild.
2
1595
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 and then performing the appropriate action. But I don't find any way to retrieve any info telling me which specific MenuItem sends a click event at the moment. The sender and e parameters seem to carry some very general information, not from a...
5
6574
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) .... TM = New ContextMenu
7
9558
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 subroutine Let's say theres a sub that creates buttons and I want it to receive as a parameter the address of the sub that handles the OnClick event for the button being created How do I pass such a parameter Thanks in advance Richar
4
1600
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 to store a little extra information for each item. Previously, I was writing: MyMenu.MenuItems.Add ( "the text label", New EventHandler(AddressOf
2
2321
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: AddHandler ButtonNew.Click, AddressOf My_Passed_Function I thought I could use a delegate but that doesn't seem to be working. Am I on the right track?
9
2109
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 sender, System.EventArgs e) I can not figure out how can the System.EventArgs e be helpful to me. Can I get from the System.EventArgs e the Point where the mouse click for
0
8384
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
8820
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
8718
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
8499
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8601
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6162
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
4150
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2726
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 we have to send another system
2
1937
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.

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.