Solved

what is object sender / System.EventArgs e?

Posted on 2003-11-02
1
836 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
Comment Utility
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

IT, Stop Being Called Into Every Meeting

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Recently while returning home from work my wife (another .NET developer) was murmuring something. On further poking she said that she has been assigned a task where she has to serialize and deserialize objects and she is afraid of serialization. Wha…
Real-time is more about the business, not the technology. In day-to-day life, to make real-time decisions like buying or investing, business needs the latest information(e.g. Gold Rate/Stock Rate). Unlike traditional days, you need not wait for a fe…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…
This demo shows you how to set up the containerized NetScaler CPX with NetScaler Management and Analytics System in a non-routable Mesos/Marathon environment for use with Micro-Services applications.

763 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

6 Experts available now in Live!

Get 1:1 Help Now