I have a code:
public class Layout : UserControl
{
protected void DisplayX_DisplayClicked(object sender, DisplayEventArgs e)
{
CurrentDisplay = (CameraPanel)sender;
}
}
'Layout' is a base class for my other layouts. For example, I have a 'Layout1' derived from base class 'Layout'. Layout1 has an element Display01. Display01 has an DisplayClicked event. I'm trying to assign DisplayX_DisplayClicked via Visual Studio Designer to DisplayClicked event of Display01.
public partial class Layout1 : Layout
{
private CameraPanel Display01;
}
It gives me an error:
The method 'xxx' cannot be the method for an event because a class this class derives from already defines the method.
How to use method from base class as a eventhandler of derived class ? Is it possible ? If so, how. If no, why.
The designer can't handle that, but you can do it in code just fine. In the constructor for Layout1, just write:
public Layout1()
{
InitializeComponent();
this.Display01.DisplayClicked += base.DisplayX_DisplayClicked;
}
Alternately, you could let the designer generate a method named Display01_DisplayClicked, and then implement it as:
private void Display01_DisplayClicked(object sender, DisplayEventArgs e)
{
base.DisplayX_DisplayClicked(sender, e);
}
That's a lot more verbose, so I would do it the first way, but it would let the designer be aware that there was a handler for that event.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With