Solved

what is object sender / System.EventArgs e?

Posted on 2003-11-02
1
843 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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
VB.NET 2008 - Windows Protected Your PC 7 41
RLDC Reporting in Visual studio 11 30
SSIS On fail action 5 38
Code enhancement 4 21
The object model of .Net can be overwhelming at times – so overwhelming that quite trivial tasks often take hours of research. In this case, the task at hand was to populate the datagrid from SQL Server database in Visual Studio 2008 Windows applica…
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…
Microsoft Active Directory, the widely used IT infrastructure, is known for its high risk of credential theft. The best way to test your Active Directory’s vulnerabilities to pass-the-ticket, pass-the-hash, privilege escalation, and malware attacks …

860 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