namespace Event{ //public delegate void MyDelegate(); public class EventProgram:Form { //public static event MyDelegate MyEvent;
public EventProgram() { Button clickMe = new Button();
clickMe.Parent = this; clickMe.Text = "Click Here"; clickMe.Location = new Point( (ClientSize.Width - clickMe.Width) / 2, (ClientSize.Height - clickMe.Height) / 2);
clickMe.Click += new EventHandler(OnClickMeClicked);
// MyEvent += new MyDelegate(OnStartEvent); // MyEvent(); }
public void OnClickMeClicked(object sender, EventArgs ea) { MessageBox.Show("My Button is Clicked."); }
public void OnStartEvent() { MessageBox.Show("My Start Event Started :) "); } static void Main() { Application.Run(new EventProgram()); } }}
In the above example we are using a windows form containing a button only. Clicking on that button the registered method will be executed.