Solved

what is object sender / System.EventArgs e?

Posted on 2003-11-02
1
838 Views
Last Modified: 2008-03-10
Example:

private void menuItem2_Click(object sender, System.EventArgs e)
            {
                  Application.Exit();
            }


1)  What is object sender?  (Please give a few examples of its use)

2)  What is System.EventArgs e?  (Again, please give a few examples of how to use it)


Thanks!!

Tom
0
Comment
Question by:knowlton
1 Comment
 
LVL 9

Accepted Solution

by:
tinchos earned 500 total points
ID: 9667839
From Programming in C# Second Edition

By convention, event handlers in the .NET Framework return void and take two parameters.

The first parameter is the source of the event; that is, the publishing object.

The second parameter is an object derived from EventArgs. It is recommended that your event handlers follow this design pattern.

EventArgs is the base class for all event data. Other than its constructor, the EventArgs class inherits all its methods from Object, though it does add a public static field empty, which represents an event with no state (to allow for the efficient use of events with no state). The EventArgs derived class contains information about the event.

For example

The declaration for the SecondChangeHandler delegate (executed when a clock changes it's second) is:

public delegate void SecondChangeHandler(
object clock,
TimeInfoEventArgs timeInformation
);

This declares the delegate. As stated earlier, by convention an event handler returns void and takes two parameters: the source of the event (in this case clock) and an object derived from EventArgs -- in this case, TimeInfoEventArgs. TimeInfoEventArgs is defined as follows:

public class TimeInfoEventArgs : EventArgs
{
  public TimeInfoEventArgs(int hour, int minute, int second)
  {
     this.hour = hour;
     this.minute = minute;
     this.second = second;
  }
  public readonly int hour;
  public readonly int minute;
  public readonly int second;
}

The TimeInfoEventArgs object will have information about the current hour, minute, and second. It defines a constructor and three public, read-only integer variables.

Hope this helps

Tincho
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

861 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

23 Experts available now in Live!

Get 1:1 Help Now