How to enumerate a ToolStripMenuItems's events

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

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
 
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.
 
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 said:
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]
- (e-mail address removed)

Lilian said:
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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top