Ban*_*hee 5 c# inheritance winforms
我有这样的事情:
public class WinformBase : Winform
{
public WinformBase (){
this.Activated += new System.EventHandler(this.MyTest1_Activated);
}
private void MyTest1_Activated(object sender, EventArgs e)
{
MyController.TopFormActivated(this);
}
}
public class MyForm : WinformBase
{
public MyForm (){
this.Activated += new System.EventHandler(this.MyTest2_Activated);
}
private void MyTest2_Activated(object sender, EventArgs e)
{
MyController.TopFormActivated(this);
}
}
Run Code Online (Sandbox Code Playgroud)
问题是该事件仅在MyForm中触发而不在Winform基础中触发?
为什么会如此,我怎样才能触发事件WinformBase呢?
这是我解决问题的方法:
public class WinformBase : Winform
{
public WinformBase (){
}
protected override void OnActivated(EventArgs e)
{
base.OnActivated(e);
Controller.MyMethod();
}
}
public class MyForm : WinformBase
{
public MyForm (){
}
}
Run Code Online (Sandbox Code Playgroud)