Click to See Complete Forum and Search --> : "handles" in C#
birthjay
Mar 14th, 2005, 08:21 PM
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#
mendhak
Mar 14th, 2005, 10:24 PM
In C#, you subscribe to an event like so:
//example, the form's click handler
this.Click += new System.EventHandler(this.Form1_Click);
And then use Form1_Click{}
mendhak
Mar 14th, 2005, 10:25 PM
The easy way:
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:
// 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.
}
5. Add the appropriate code to the event handler.
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vbcon/html/vbtskcreatingeventhandlers.asp
birthjay
Mar 15th, 2005, 07:19 AM
Thank you!
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.