NGWS SDK Documentation  

This is preliminary documentation and subject to change.
To comment on this topic, please send us email at ngwssdk@microsoft.com. Thanks!

Introduction to Event-Handling Methods

An event-handling method is a method that is bound to an event. When the event is raised, the code within the event-handling method is executed. Each event-handling method provides two parameters that allow you to handle the event properly. The following example shows an event-handling method for a Button control's Click event:

The first parameter, sender, provides a reference to the object that raised the event. The second parameter, e in the example above, passes an object specific to the event that is being handled. By referencing the object's properties (and sometimes, its methods), you can obtain information such as the location of the mouse for mouse events or data being transferred in drag-and-drop events.

Typically each event produces an event-handling method with a different event object type for the second parameter. Some event-handling methods, such as those for the MouseDown and MouseUp events, have the same object type for their second parameter. For these types of events, you can use the same event-handling method to handle both events.

[Visual Basic]
Public Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)

End Sub
[C#]
private void Button1_Click(object sender, EventArgs e) {

}

You can also use the same event-handling method to handle the same event for different controls. For example, if you have a group of RadioButton controls on a form you could create a single event-handling method for the Click event and have each control's Click event bound to the single event-handling method. For more information, see Connecting Multiple Events to a Single Event-handling method.

See Also

Event Handling | Introduction to Events | Creating Event-Handling Methods at Run Time for Win Forms