views:

111

answers:

3

Is there any way to set an event handler without doing it manually in the classname.designer.cs file other than double clicking the UI element?

+2  A: 

If I follow your question correctly, you can just do it in your code-behind like this:

myButton.Click += myHandler;

Or you could use an anonymous delegate:

myButton.Click += delegate
{
    MessageBox.Show("Clicked!");
};

HTH, Kent

Kent Boogaart
+1  A: 

Sure. Use myControl.Event += new EventHandler(SomeHandlerMethodInYourClass) somewhere during initialization, e.g. in the form's constructor.

Dan C.
+2  A: 

Click on the lightning bolt icon in the Properties window. Double-click the event you want to implement.

Hans Passant