views:

260

answers:

3

How to add event listeners in C#?

+1  A: 

You should try searching, good artice; http://www.devarticles.com/c/a/C-Sharp/Creating-Custom-Delegates-and-Events-in-C-sharp/

Dustin Laine
+3  A: 
    comboBoxHost.KeyDown += new System.Windows.Forms.KeyEventHandler(Fire_KeyDown);

where KeyEventHandler is a delegate, and Fire_KeyDown is a local method with the delegate signature.

Or using an anonymous delegate, as in:

button1.Click += delegate(System.Object o, System.EventArgs e)
                   { System.Windows.Forms.MessageBox.Show("Click!"); };
Simon Chadwick
+1  A: 

A good example is here The Simplest C# Events Example Imaginable

Shaji