Example

using System;
namespace Samples
{
  public class EventHandlerSample
  {
    public class MyButton
    {
      public event EventHandler MouseClick;
      public void SimulateButtonClicked()
      {
        if(MouseClick != null)
          MouseClick(this, EventArgs.Empty);
      }
    }
    public static void Main()
    {
      MyButton b =  new MyButton();
      b.MouseClick += new EventHandler(ButtonClicked);
      b.SimulateButtonClicked();
    }
    public static void ButtonClicked(object sender,
                                     EventArgs args)
    {
      Console.WriteLine("Sender is {0}", sender);
    }
  }
}
The output is
Sender is Samples.EventHandlerSample+MyButton

Get .NET Framework Standard Library Annotated Reference, Volume 1: Base Class Library and Extended Numerics Library now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.