Get EventHandler

TaleOfTimes

Newcomer
Joined
Dec 20, 2005
Messages
15
hello all!

I need a little help, maybe someone here can help me out.

I have a menu, now, for reasons too long and too irrelevant to write down, I create a toolbox out of said menu. Everything has gone well until I wanted to have the buttons on the toolbox call the same click event as their respective menu item.

So is there even a way to add an EventHandler to the Click event of a new object that points to another object's EventHandler

in pseudocode I suppose it'd be something like this:
newObject.Click = oldObject.Click

Thx
 
Which language are you using?

Well, here is the syntax for dynamic event handlers in VB and C#, in case you aren't familiar.

Assuming that there is an event handler already declared by the name of oldObject_Click...
Code:
[Color=Violet]<VB>[/Color]
[Color=Blue]AddHandler [/Color]newObject.Click, [Color=Blue]AddressOf [/Color]oldObject_Click

[Color=Violet]<C#>[/Color]
newObject.Click += [Color=Blue]new [/Color]EventHandler(oldObject_Click);
[Color=Violet]<C# 2>[/Color]
newObject.Click += oldObject_Click;

You can't, however, read which event handlers are assigned to an event (except possibly by reflection). You can't really write code that says "take the old control and assign its click event handler to my new controls click event." I don't know if there is really a way to do what it sounds like you want to.
 
Thx for the reply

I'm using C# and it's the last part of your post that made me sad... lol.

Wow I can't believe you can't simply point to another object's event. I guess i'll have to find some other way to do it.

Thx again
 
If you read up on MSIL (real exciting stuff) you will understand that this limitation is based on the way DotNet implements the event system. Under the hood a class must declare a function to add an event handler and to remove an event handler, and how they store and manage event handlers internally is entirely up to the programmer (in MSIL and optionally C#) or compiler (all other languages). Since there is no standard way to manage event handlers, there is no standard way to read event handlers. Sorry.
 
Back
Top