I have a class which trying to register an event in another class.
In class A I have a method as shown below:
public void Mouse_Down(object sender, MouseEventArgs e)
{
}
I am registering the event in class B like so:
ClassA classA = new ClassA();
classA.MouseDown += new MouseEventHandler(classA.Mouse_Down);
When click nothing is happening. Does anyone know what the problem could be.
Set a breakpoint at the event triggering code (of classA) and check your EventHandlers collection. I bet there is no one registered and you’re messing with classA instances.
It is also possible that you will never get your breakpoint, which means that your event is not fired.
Anyway the thing that you want to do looks a little weird for me.
Edit:
Have you tried to register a different method to the same event ‘in normal way’ (ex. from a ClassA constructor)? If you don’t have access to event triggering code, that is to best way to check if there are proper handlers registered, at the moment of event being fired.