C#

Moderators: None (Apply to moderate this forum)
Number of threads: 2712
Number of posts: 5738

This Forum Only
Post New Thread
Single Post View       Linear View       Threaded View      f

Report
what is the meaning of ( object sender, System.EventArgs e ) Posted by richard_u on 8 Nov 2005 at 5:36 AM

Hello,

what is the meaning of ( object sender, System.EventArgs e )
when they are together as parameters of function of event of
a button, like :
public void rotation_Click(object sender, System.EventArgs e);


Bye,

richard

Report
Re: what is the meaning of ( object sender, System.EventArgs e ) Posted by iwilld0it on 8 Nov 2005 at 7:19 AM
Under .NET framework, by convention, all events have this format.

The reasoning for the first argument is that a single event handler can be attached to the same event like so.

btnTestA.Click += new EventHandler(btnTest_Click);
btnTestB.Click += new EventHandler(btnTest_Click);


When btnTestA and btnTestB is clicked, the btnTest_Click event handler will be fired. The "object sender" portion will be a reference to whatever one of the buttons was clicked ...

private void btnTest_Click(object sender, EventArgs e)
{
    Button test = sender as Button;

    // etc ...
}


The EventArgs portion is a way to pass extra information to the event handler. In the case above, EventArgs is a base class and no real extra information is passed. However, alot of events use a derivative of EventArgs, which contain extra information.




:
: Hello,
:
: what is the meaning of ( object sender, System.EventArgs e )
: when they are together as parameters of function of event of
: a button, like :
: public void rotation_Click(object sender, System.EventArgs e);
:
:
: Bye,
:
: richard
:
:

Report
I want an easier Explaination Posted by richard_u on 9 Nov 2005 at 8:34 AM
This message was edited by richard_u at 2005-11-9 8:35:5

Hello,

I do not understand this answer.
I want an easier Explaination.

Bye,

Richard


Report
Re: I want an easier Explaination Posted by iwilld0it on 9 Nov 2005 at 10:00 AM
The "sender" argument is the object that raised the event. The EventArgs argument is extra information passed to the event.

So if u clicked a button, then the sender would be the button that u have clicked.

Plain and simple.

Now the fact that ALL events follow this format is a matter of convention. It is a coding practice / pattern adopted by Mirosoft.

If you do not understand this, then you really must pick up a .NET book, since most devote a full chapter to this topic.
Report
Re: I want an easier Explaination Posted by Eyveneen on 21 Feb 2012 at 12:18 PM
I was looking for the same answer to your question. Maybe this link will help.

http://msdn.microsoft.com/en-us/library/system.eventhandler.aspx



 

Recent Jobs

Official Programmer's Heaven Blogs
Web Hosting | Browser and Social Games | Gadgets

Popular resources on Programmersheaven.com
Assembly | Basic | C | C# | C++ | Delphi | Flash | Java | JavaScript | Pascal | Perl | PHP | Python | Ruby | Visual Basic
© Copyright 2011 Programmersheaven.com - All rights reserved.
Reproduction in whole or in part, in any form or medium without express written permission is prohibited.
Violators of this policy may be subject to legal action. Please read our Terms Of Use and Privacy Statement for more information.
Operated by CommunityHeaven, a BootstrapLabs company.