Hi,
lets say you have
public class MyForm : Form
{...}
Then you can use reflection over MyForm class, extract the list of all
events and subscribe a common method to everyone of them. And in this
method do whatever you want: Debug.Write, log in file, whatever.
All event handlers have the form MyHandler(object sender, EventArgs e),
so your handler can be:
void MyHandler(....)
{
Control control = sender as Control;
if (control != null)
{
//now here you can use control.Name to get who is the sender
//and use StackTrace to get the caller method, it should be
//something like OnXxxxx, so you will know what event was raised
}
}
And ... if you want all events for underlying controls, you have
complicate the things, and to iterate thru Controls collection of every
control, to get the events for every control and to subscribe them to
your handler as well.
But ... I doubt if you need such a thing. If you need to track down in
what sequence are raised the events to which you already has attached
handlers, you can use the Control.Events property to get all event
handlers already attached. And for every delegate in that list, you can
use Delegate.Combine to add your own tracking handler.
Sunny
In article <00**********************************@microsoft.co m>,
ar*******@topco.com says...
Hi,
this seems like something so basic that there must be some way to do it...Is there a way for Visual Studio or some other tool to let me see Events as they are raised in an application?
For example, I've created a form with two fields. I would like to be able to see ALL the events for the application as I run/debug it. I want to know that clicking on field1 and then field2 produces: fld1.enter, fld1.leave, fld2.enter, etc.
I guess I should stipulate that I don't want to have to place breakpoints or debug writelines in the code. I don't want to have to anticipate which event handlers will be called. I want to see if events I didn't even expect are being raised.