Event and event handler : Event : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Event »

 

Event and event handler









    
using  System;
using  System.Collections.Generic;
using  System.Reflection;
using  System.Runtime.InteropServices;

class  MyClass  :  IDisposable
{
        public  event  EventHandler  OnInitialized;
        public  event  EventHandler  OnDisposed;

        public  void  Init()
        {
                //  Initialize  our  state...
                EventHandler  onInit  =  OnInitialized;
                if  (onInit  !=  null)
                        onInit(this,  new  EventArgs());
        }

        public  void  Dispose()
        {
                //  Release  our  state...
                EventHandler  onDisp  =  OnDisposed;
                if  (onDisp  !=  null)
                        onDisp(this,  new  EventArgs());
        }
}

public  class  MainClass
{
      public  static  void  Main(){
                using  (MyClass  f  =  new  MyClass())
                {
                        f.OnInitialized  +=  delegate  {  Console.WriteLine("init");  };
                        f.OnDisposed  +=  delegate  {  Console.WriteLine("disposed");  };
                        f.Init();
                }                        
      }

}
    
   
  
   



Output

init
disposed


HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Event