Here is a very simple example:
Code:
using System;
using System.Windows.Forms;
using System.Drawing;
public class MyEventHandler : Form
{
public MyEventHandler()
{
// Just setup a very very simple UI
Size = new Size(200, 200); // Size of window
// Create new button with the created window as parent
Button myButton = new Button();
myButton.Parent = this;
myButton.Text = "Click me";
// When button is clicked, run OnButtonClick
myButton.Click += new EventHandler(OnButtonClick);
}
// Display message box when button has been clicked
public void OnButtonClick(object sender, EventArgs e)
{
MessageBox.Show("You clicked me");
}
public static void Main()
{
Application.Run(new MyEventHandler());
}
}