Reputation: 12517
I am a Java programmer moving to .NET development and have about 5 years programmign experience. I usually write all my code in a text editor, omitting the IDE side of things. With Visual C# I am using the Visual Studio 2010 IDE. In order to get to grips with the interface I am following official Microsoft tutorials.
My question relates to creating event handlers for control items:
When designing, say, a windows form application, it is possible to drag controls directly onto the form (i.e. buttons, check boxes etc). The tutorial nstructs users to double click on a button control and double click on it to create the click event handler in the .cs file. This works absolutely fine and creates the following piece of code for a button with a (name) of showButton:
private void showButton_Click(object sender, EventArgs e)
{
}
Where is the link between the button and the event handler stored? As in, how does the compiler know which button the above event handler maps to?
Upvotes: 3
Views: 339
Reputation: 1888
Take a look at YourForm.Designer.cs at InitializeComponent()
method.
You'll find the code similar to
//
// show
//
this.show.Location = new System.Drawing.Point(10, 10);
this.show.Name = "show";
this.show.Size = new System.Drawing.Size(75, 23);
this.show.TabIndex = 0;
this.show.Text = "button1";
this.show.UseVisualStyleBackColor = true;
this.show.Click += new System.EventHandler(this.ShowClick);
Upvotes: 8