TaleOfTimes Posted February 7, 2007 Posted February 7, 2007 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 Quote
Leaders snarfblam Posted February 8, 2007 Leaders Posted February 8, 2007 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. Quote [sIGPIC]e[/sIGPIC]
TaleOfTimes Posted February 8, 2007 Author Posted February 8, 2007 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 Quote
Leaders snarfblam Posted February 8, 2007 Leaders Posted February 8, 2007 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. Quote [sIGPIC]e[/sIGPIC]
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.