Reputation: 1199
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
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
Reputation: 942358
Click on the lightning bolt icon in the Properties window. Double-click the event you want to implement.
Upvotes: 2
Reputation: 3683
Sure. Use myControl.Event += new EventHandler(SomeHandlerMethodInYourClass)
somewhere during initialization, e.g. in the form's constructor.
Upvotes: 1