473,387 Members | 1,470 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,387 software developers and data experts.

How to enumerate a ToolStripMenuItems's events

Hi,

In a Windows Form I created a set of ToolStripMenuItems.

I am looking for a method to list, for a specific ToolStripMenuItem, the
Click EventHandlers (if any) so as to add them to another control.

I found System.Reflection.EventInfo class which seems to achieve this kind
of enumeration but I did not found how to make it work.

PS : I'm using VS2K5 and FW 2.0.

Thank you in advance
Mar 28 '07 #1
2 2053
Lilian,

The EventInfo class will show you the events on a type, but it won't
help you get at the delegates. What you really want is to find the
FieldInfo instance which corresponds to the field that is the backing store
for the event.

Unfortunately, there is no concrete link between an event and that
field. You would have to develop a heuristic to figure out what the
association is.

Because of this, I would ask what exactly you are trying to do this for.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lilian" <Li****@discussions.microsoft.comwrote in message
news:57**********************************@microsof t.com...
Hi,

In a Windows Form I created a set of ToolStripMenuItems.

I am looking for a method to list, for a specific ToolStripMenuItem, the
Click EventHandlers (if any) so as to add them to another control.

I found System.Reflection.EventInfo class which seems to achieve this kind
of enumeration but I did not found how to make it work.

PS : I'm using VS2K5 and FW 2.0.

Thank you in advance

Mar 28 '07 #2
Hi Nicholas,

What I am trying to do is to duplicate menu items in my application.

If you take a look at MS Outlook (2003 version for instance) you may create
a new message, contact, task ... from the "File..New" menu but you can also
do it by clicking in the toolbar on the "New" button which gives the exact
same list of choices.

That is exactly what I want in my own project : if I edit/add a menu item in
the "File..New" window menu I wouls like it to be repercuted to the "New"
button.

Actually I managed to dynamically duplicates the menu items, by browsing the
menu items collection, but I cannot find how to make the dynamic menu items
behave like the original ones.

I hope this is clear ....

Thank anyway for your information which seems to mean that there is no
straight way I couldn't find.

Lilian

"Nicholas Paldino [.NET/C# MVP]" wrote:
Lilian,

The EventInfo class will show you the events on a type, but it won't
help you get at the delegates. What you really want is to find the
FieldInfo instance which corresponds to the field that is the backing store
for the event.

Unfortunately, there is no concrete link between an event and that
field. You would have to develop a heuristic to figure out what the
association is.

Because of this, I would ask what exactly you are trying to do this for.

Hope this helps.

--
- Nicholas Paldino [.NET/C# MVP]
- mv*@spam.guard.caspershouse.com

"Lilian" <Li****@discussions.microsoft.comwrote in message
news:57**********************************@microsof t.com...
Hi,

In a Windows Form I created a set of ToolStripMenuItems.

I am looking for a method to list, for a specific ToolStripMenuItem, the
Click EventHandlers (if any) so as to add them to another control.

I found System.Reflection.EventInfo class which seems to achieve this kind
of enumeration but I did not found how to make it work.

PS : I'm using VS2K5 and FW 2.0.

Thank you in advance


Mar 28 '07 #3

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

Similar topics

3
by: Cliff Harris | last post by:
I have an odd question that I'm hoping someone can help with. I simply (or not simply?) need to enumerate through all of the data types in the .Net framework. I do understand that if this is...
1
by: smichr | last post by:
I see that there is a thread of a similar topic that was posted recently ( enumerate with a start index ) but thought I would start a new thread since what I am suggesting is a little different. ...
2
by: eight02645999 | last post by:
hi, i am using python 2.1. Can i use the code below to simulate the enumerate() function in 2.3? If not, how to simulate in 2.1? thanks from __future__ import generators def...
8
by: Dustan | last post by:
Can I make enumerate(myObject) act differently? class A(object): def __getitem__(self, item): if item 0: return self.sequence elif item < 0: return self.sequence elif item == 0: raise...
21
by: James Stroud | last post by:
I think that it would be handy for enumerate to behave as such: def enumerate(itrbl, start=0, step=1): i = start for it in itrbl: yield (i, it) i += step This allows much more flexibility...
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...
1
by: =?Utf-8?B?bGpsZXZlbmQy?= | last post by:
I've noticed that if you click on a Windows.Forms.ToolStripButton then a MouseLeave event will not occur until the button is released. ToolStripMenuItems on the other hand will raise a MouseLeave...
0
by: Earl | last post by:
Anyone know of a good example on databinding to ToolStripMenuItems? There used to be a Billy Hollis article link, but MSDN is full of dead links these days, so I've given up trying to find that one.
5
by: Academia | last post by:
I use to do this: Dim index As Integer = CType(sender, MenuItem).Index but ToolStripMenuItems do not have an Index property so I can set the Tag or MergeIndex property of those items and use...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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...

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.