what is the meaning of ( object sender, System.EventArgs e ) - Programmers Heaven

Howdy, Stranger!

It looks like you're new here. If you want to get involved, click one of these buttons!

Categories

Welcome to the new platform of Programmer's Heaven! We apologize for the inconvenience caused, if you visited us from a broken link of the previous version. The main reason to move to a new platform is to provide more effective and collaborative experience to you all. Please feel free to experience the new platform and use its exciting features. Contact us for any issue that you need to get clarified. We are more than happy to help you.

what is the meaning of ( object sender, System.EventArgs e )

richard_urichard_u Posts: 2Member

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

Comments

  • iwilld0itiwilld0it Posts: 1,134Member
    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.

    [code]
    btnTestA.Click += new EventHandler(btnTest_Click);
    btnTestB.Click += new EventHandler(btnTest_Click);
    [/code]

    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 ...

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

    // etc ...
    }
    [/code]

    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
    :
    :

  • richard_urichard_u Posts: 2Member
    [b][red]This message was edited by richard_u at 2005-11-9 8:35:5[/red][/b][hr]
    Hello,

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

    Bye,

    Richard


  • iwilld0itiwilld0it Posts: 1,134Member
    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.
  • EyveneenEyveneen Posts: 1Member
    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
Sign In or Register to comment.