Hey forum,

When we make a button on our WPF form and double click on it, we get the following code generated for us:

private void button1_Click(object sender, EventArgs e)


Now obviously, the button is a _Click method which basically means that whatever code that goes within the body of this method will be executed when the button is 'Clicked'.

With that said, can anyone be so kind to actually explain the signature of the method:

(object sender, EventArgs e)

It would really help me get an understanding of what that actually means. I've made a bunch of UI's and not been bothered to investigate as to what some of the pre-generated code actually mean.

All help is extremely and gratefully appreciated.


7 Years
Discussion Span
Last Post by Usmaan

I think the 'object sender' is the control that generated the event, it could be a button on your form or the form it's self.

The event args has more information about the event.

Make a button on your form generate an event when clicked and try this:

Button btn = sender as Button;
btn.Text = "Clicked!";

You can get all this information from MSDN, which if you haven't checked out it's probably important that you do so.
if you scroll down you will see an event named "Click"

Edited by pseudorandom21: n/a


Ah okay. I'll do that. And oh, this is my first time in my life that I have seen the 'as' keyword but, I can figure out what your code means. You're correct about msdn holding valuble information but, sometimes I feel almost dislexic when attempting to make sense of the information.

Thanks for the reply though, much appreciated.


This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.