Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Event handlers in Visual Studio

Tags:

c#

events

handler

When I try to create an event handler eg. button click in c#, if I write the code manually in code behind class, the event handler won't be called; Whereas if I double click the button on the form and the VS auto generates the event, it will work perfectly. What is the reason behind this behavior?


1 Answers

There is a Form.Designer.cs file that hooks up the events for each individual form (each form has it's own designer file).

Open that and you'll find lines like:

button1.Click += button1_Click;

..etc.

As below:

Designer file

Click wiring

like image 77
Simon Whitehead Avatar answered Dec 05 '25 23:12

Simon Whitehead