using System; namespace Samples { public delegate void CustomEventHandler(object sender, EventArgs e); class EventSample { public static void Sample() { Button button = new Button(); button.Click += new CustomEventHandler(Button_Click); button.OnClick(); } private static void Button_Click(object sender, EventArgs e) { System.Console.WriteLine("Button clicked!"); } } class Button { public event CustomEventHandler Click; public void OnClick() { if (Click != null) Click(this, EventArgs.Empty); } } }