c# - Event Handlers automatically created by WinForms Designer -


I just moved from VB.NET to C #. In VB, we use the handles section to connect an event handler to a sub.

It seems that it is not present in C #.

After creating a simple application with a button, I realized that the Window Form Designer has created an event handle on its button 1_Click function (automatically clicking it), with this code Form1.Designer.cs :

this.button1.Click + = New System.EventHandler (this.button1_Click);

But in VB, in the Function Header, WinForms Designer creates handles clauses in my class.

Then, C # creates the default event handler in the designer file, while VB The main square makes where the control remains.

Is that correct? Am I missing something here?

You are right that the VB.NET code in handles Related with events variable decorator) These are present in the VB.NET as a Hold from the classic VB, and their use is overhead (generated IL actually tracks everywhere that separating the variable And all the functions that handle

if you use VBNET form or IL fairy for control , You will actually know that every one WithEvents variable , and the center takes care to remove all real handlers from the old value (it is non-null ) And attach them to the new value (assuming it is non-null).

Analog VB.NET for event Handling is the Adhendler statement for C #. P>


Comments