Inherited event handlers

J

joe

Happy New Year to you all and may the source be with you!

I have a class, which handles an event and I derive from
this class. I dont want the event handler in the base
class to be called anymore as it does things I dont want
it to do. I want to handle the event in the derived class.
How do I do it?
One way is to declare the event handler in the base class
as protected virtual.
Is there another way?

class A
{
public ClassWithEventCalledMyEvent c;
this.c.MyEvent+=new EventHandler(MyEventHandler);
private void MyEventHandler(...)
{
// I DONT WANT THIS CALLED IN THE DERIVED CLASS
}
}

class B:A
{
this.MyEvent+=new EventHandler(MyDerivedEventHandler);
private void MyDerivedEventHandler(...)
{
// I WANT THIS CALLED ONLY
}
}

Thanks,
 
W

WoodBeeProgrammer

the issue is how you register the event handler.. whereever your event +=
handler statement is, that's where the inheritance will or won't affect the
derived class.

HTH.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top