Use delegate to add an event handler to a Button : Button : GUI Windows Forms C# Examples


C# Examples » GUI Windows Forms » Button »

 

Use delegate to add an event handler to a Button








    
using  System;
using  System.Drawing;
using  System.Windows.Forms;

public  class  ButtonEventDelegate  :  System.Windows.Forms.Form
{

    private  Button  btn;

    public  ButtonEventDelegate()
    {
                Text  =  "Hello  World";

        btn  =  new  Button();
        btn.Location  =  new  Point(50,50);
        btn.Text  =  "Goodbye";
        btn.Click  +=  new  System.EventHandler(btn_Click);

        Controls.Add(btn);
    }

    static  void  Main()  
    {
        Application.Run(new  ButtonEventDelegate());
    }

    private  void  btn_Click(object  sender,  EventArgs  e)
    {
        Application.Exit();
    }
}
    
   
  
   




HTML code for linking to this page:

Follow Navioo On Twitter

C# Examples

 Navioo GUI Windows Forms
» Button