[RESOLVED] [2005] What events is my procedure handling?
Hi all,
I am studying up on Events and have a question I couldn't find an answer to.
Let's say I create a number of controls at runtime and use AddHandler to connect the control's Click event to myProcedure at some point. Is there a way to go back later in the code and see what events my procedure is handling? i.e. If myProcedure is handling TextBox1.Click then do something.
I'm not sure why or if I would ever even need to do this but the question popped into my head and I'm just curious.
Thanks for any insight. :)
Re: [2005] What events is my procedure handling?
Nothing obvious in the EventInfo type...hmm - probably not possible.
Re: [2005] What events is my procedure handling?
You could probably have the event handler pop up a message box or something and you could try each control to see which is triggering it.
Re: [2005] What events is my procedure handling?
Not unless you comment its use inside the sub *HINT*HINT*. If you are creating controls on the fly then there is really no way unlike dragging a control onto a form and adding (or having it added for you) the "Handles textbox.click" to it.
*sidenote* if you are creating controls on the fly then: Directcast(Sender, ObjectType) will be your BEST friend, because you can do different things all in one sub with various types of controls!! Of course you may have already known that and I just wasted my breath......:lol:
Good Luck in your studies!!
D
Re: [2005] What events is my procedure handling?
Thanks for the responses. :thumb:
I was wondering if there was some built-in way to do this. Going to leave this unresolved for a bit just in case anybody else wants to chime in.
Re: [RESOLVED] [2005] What events is my procedure handling?
Not got it working as yet, but MulticastDelegate.GetInvocationList seems to be the keystone to this puzzle...
Re: [RESOLVED] [2005] What events is my procedure handling?
If you figure it out let us know.
However a less elegant approach might be to store a reference to the Delegate in the tag of the object as it's being created.
Then later if you want to know which Delegates are pointing to the Sub, just iterate through all of the controls tags, check each tag's delegate Method (i.e. DelegateName.Method) to see if it's pointing to the Sub you are interested in.
but I think this will only work for instance methods that are targets of a delegate (but it might be worth a try anyway).
That might also lead to issues of not removing all delegate references when you think you are later on (because some might still be in the tags).
Re: [RESOLVED] [2005] What events is my procedure handling?
Another option along the lines of what fourblades proposes would be to create your own control, have it inherit the textbox and add a delegate property to it. Not sure of what all the details would be but I do not believe it would be too involved...../shrug
Good Luck,
D
Re: [RESOLVED] [2005] What events is my procedure handling?
Thanks for the additional replies. I haven't played with anything yet, but when I do decide that I need to do something like this, I'm coming directly back to this thread. :bigyello: