You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

33 lines
701 B

using System;
namespace Samples.Event
{
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);
}
}
}