Robert Wilkinson
Robert Wilkinson

Reputation: 1199

Setting an Event handler without doing it manually in the classname.designer.cs file

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?

Upvotes: 0

Views: 186

Answers (3)

Kent Boogaart
Kent Boogaart

Reputation: 178820

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!");
};

Upvotes: 2

Hans Passant
Hans Passant

Reputation: 942358

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

Upvotes: 2

Dan C.
Dan C.

Reputation: 3683

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

Upvotes: 1

Related Questions