In VB.NET I can use the "Handle" word to cause separate controls to react to the same event. How do I do this in C#
Printable View
In VB.NET I can use the "Handle" word to cause separate controls to react to the same event. How do I do this in C#
In C#, you subscribe to an event like so:
And then use Form1_Click{}PHP Code://example, the form's click handler
this.Click += new System.EventHandler(this.Form1_Click);
The easy way:
http://msdn.microsoft.com/library/de...nthandlers.aspQuote:
To create an event handler in C# or C++
1. Click the form or control that you want to create an event handler for.
2. In the Properties window, click the Events button ().
3. In the list of available events, click the event that you want to create an event handler for.
4. In the box to the right of the event name, type the name of the handler and press ENTER.
Tip Name the event handler according to the functionality of the event; for example, for the Click event, you can type StartProcess as the event handler.
The Code Editor appears, showing the code for the form, and an event handler method is generated in your code similar to the following:
5. Add the appropriate code to the event handler.PHP Code:// C#
private void StartProcess(object sender, System.EventArgs e)
{
// Add event handler code here.
}
// C++
private:
System::Void StartProcess(System::Object * sender,
System::EventArgs * e)
{
// Add event handler code here.
}
Thank you!