Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Activated in baseclass not triggered?

I have something like this :

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);
      }
}

The problem is that the event is only triggered in MyForm and not in the Winform base?
Why is that so, and how can I have the event triggered in WinformBase too?

like image 270
Banshee Avatar asked Nov 17 '11 13:11

Banshee


1 Answers

This is my solution to the problem :

public class WinformBase : Winform
{
     public WinformBase (){
     }

    protected override void OnActivated(EventArgs e)
    {
        base.OnActivated(e);
        Controller.MyMethod();
    }

}

public class MyForm : WinformBase
{
      public MyForm (){
      }
}
like image 183
Banshee Avatar answered Nov 07 '22 04:11

Banshee