namco
namco

Reputation: 6348

How to determine if an event raised

Can you tell me how to determine which events are raised in winform or how to add all raised events to a list or to a file in c#?

Upvotes: 1

Views: 1612

Answers (5)

Jacob Seleznev
Jacob Seleznev

Reputation: 8151

To get the events that are declared or inherited by the current Type

 typeof(MyClass).GetEvents()

After that for each you can add a simple delegate

MyClass instance = new MyClass();
foreach (var e in typeof(MyClass).GetEvents())
{
   FieldInfo fi = typeof(MyClass).GetField(e.Name, 
                                       BindingFlags.NonPublic | BindingFlags.Instance);
   object value = fi.GetValue(instance);
   if (value == null)
   {
       e.AddEventHandler(instance, handler);
   }
}

Upvotes: 0

Jacob Seleznev
Jacob Seleznev

Reputation: 8151

You can use Managed Spy. It displays a list of processes in a treeview in the left side of the window and a PropertyGrid on the right side. You can expand the process to see top-level windows in that process.

When you select a control, the PropertyGrid shows properties on that control. Clicking on the Events tab will display events such as MouseMove on the currently selected control in the treeview. To begin logging events, click the Start Logging button. The output will appear as shown. enter image description here

Upvotes: 1

Daniel Hilgarth
Daniel Hilgarth

Reputation: 174457

I am not sure, I understand your question correctly, but I am still going to try and answer it:
When you subscribe to an event, your method will be called when that event is raised. In your method, you can log that the event was raised.

Upvotes: 0

IAmTimCorey
IAmTimCorey

Reputation: 16755

From your question, it sounds like you want to see each event that is fired. To do that, you would need to subscribe to every event. If you really want to go down that road, you could create one method that would read the passed-in variables and tell you what event called the method. Then you could hook that method up to every event in your winform app. The list would be enormous, but it would give you an idea of when each event was fired.

Upvotes: 1

Yochai Timmer
Yochai Timmer

Reputation: 49271

If you're talking about windows events, you need to override the WndProc() method.

Control.WndProc Method

WndProc API basics

Upvotes: 0

Related Questions