Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

  • Leaders
Posted

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...

[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.

[sIGPIC]e[/sIGPIC]
Posted

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

  • Leaders
Posted
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.
[sIGPIC]e[/sIGPIC]

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...