Solved

what is object sender / System.EventArgs e?

Posted on 2003-11-02
1
852 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:Tom Knowlton
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Summary Displaying images in RichTextBox is a common requirement with limited solutions available. Pasting through clipboard or embedding into RTF content only support static images.  This article describes how to insert Windows control objects int…
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…
Monitoring a network: why having a policy is the best policy? Michael Kulchisky, MCSE, MCSA, MCP, VTSP, VSP, CCSP outlines the enormous benefits of having a policy-based approach when monitoring medium and large networks. Software utilized in this v…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.

617 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