Simple situation(VS2005, .NET2): I have a textBox1 on a panel1. I need to track all the emitted events from this textBox1.
Actually, when I need to track a single event(TextChanged, by e.g.) from this textBox1 I add a handler to the (TextChanged event) I set then a non-blocking breackpoint that writes on the output console a message containing the function (eventhandler) name.
So, for a single event I can write this handler and set the breackpoint, but can I do something similar for all possible textbox(or other control)’s events?
alt text http://lh5.ggpht.com/_1TPOP7DzY1E/S0H5NHjXSjI/AAAAAAAAC24/tV0IiUsxwAU/s800/eventsTrack.png
More deeply, I need to know what event have place in a certain moment on the mentioned control (textBox).
Thanks.
Aviad’s post is a good start. You can use it for events of type
EventHandler. For other delegate types you can use the same technique creating handler for each type manually.If you want to be more flexible you should create event handler in runtime using
System.Reflection.Emit. Here is a detailed explanation: http://msdn.microsoft.com/en-us/library/ms228976.aspx. Scroll down to “To generate an event handler at run time by using a dynamic method” title.//EDIT
I created simple class which is able to handle all events of particular object and pass them to universal event handler. Code is based on examples from Microsoft and XTreme.NET Talk.
Basic idea
Usage
Object to attach to is passed in constructor. Next anonymous method of type
UniversalEventHandleris used to handle all events. This method receives event name aseventNameand event arguments inargs. You can set breakpoint on this method and inspect arguments in Visual Studio or print them by yourself. In this sample usage only event name is printed and can be found in Output window (menu View > Output in Visual Studio). In this example standard buttonbutton1is examined.Code