Event Args.

private void rbButtons_CheckedChanged(object sender, System.EventArgs e)

could someone break this event handler down for me....what is the purpose of the 'object sender' and 'System.EventArgs e'

[201 byte] By [Dpowers] at [2007-12-16]
# 1

This is a standard event signature where sender is the sender of the event and e contains the arguements to the event. In the case of the CheckedChanged (or most any xxxChanged) event, sender will be the the object/control that had it's Checked property changed and e is likely unused (typically set to EventArgs.Empty).

- Ray

RayManning at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...
# 2
Hi,

This event occurs when the state of a RadioButton changes. sender will contain the instance of RadioButton on which the event occured. EventArgs is the base class for all classes which contains data regarding an event.

In this case there is no data in the EventArgs, in other situations such as the KeyPress event of a Form, a class derived from EventArgs is used which would have data such as the key pressed.
private void Form1_KeyPress(object sender, KeyPressEventArgs e)
{
char ch = e.KeyChar;
}

However, to maintain a consistency in the event handling mechanism this signature is followed for all events even when EventArgs has no data.

As for the other part - the use of the sender object. This would be useful if you used the same method to handle multiple events. For example:
You can register this same EventHandler method for the CheckChanged event of a RadioButton and a CheckBox. In that case, you can utilize the sender instance to know which control the event fired on. In Visual Studio, a separate EventHandler is added for each control and so you are sure that only one control is using the EventHandler and so you rarely check what the sender is.

Regards,
Vikram

Vikram at 2007-9-9 > top of Msdn Tech,Visual C#,Visual C# General...