Installing an event handler without manually executing it in the classname.designer.cs file

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

0


source to share


3 answers


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



+2


source


If I am following your question correctly, you can simply do it in your code like this:

myButton.Click += myHandler;

      



Or you can use an anonymous delegate:

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

      

+2


source


Sure. Use myControl.Event += new EventHandler(SomeHandlerMethodInYourClass)

somewhere during initialization eg. in the form constructor.

+1


source







All Articles