Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

what is object sender / System.EventArgs e?

Posted on 2003-11-02
1
Medium Priority
?
857 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 2000 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

Veeam Task Manager for Hyper-V

Task Manager for Hyper-V provides critical information that allows you to monitor Hyper-V performance by displaying real-time views of CPU and memory at the individual VM-level, so you can quickly identify which VMs are using host resources.

Question has a verified solution.

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

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…
This article shows how to deploy dynamic backgrounds to computers depending on the aspect ratio of display
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…

715 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