Click here to Skip to main content
15,900,724 members
Home / Discussions / C#
   

C#

 
AnswerRe: How to access this variabel? Pin
Anthony Mushrow9-Oct-07 9:52
professionalAnthony Mushrow9-Oct-07 9:52 
AnswerRe: How to access this variabel? Pin
Scott Dorman9-Oct-07 9:59
professionalScott Dorman9-Oct-07 9:59 
QuestionInstallation System Pin
Ken Mazaika9-Oct-07 9:30
Ken Mazaika9-Oct-07 9:30 
AnswerRe: Installation System Pin
il_masacratore9-Oct-07 21:36
il_masacratore9-Oct-07 21:36 
Question...(object sender, System.EventArgs e) Pin
Imran Adam9-Oct-07 8:43
Imran Adam9-Oct-07 8:43 
AnswerRe: ...(object sender, System.EventArgs e) Pin
Not Active9-Oct-07 8:59
mentorNot Active9-Oct-07 8:59 
GeneralRe: ...(object sender, System.EventArgs e) Pin
Imran Adam9-Oct-07 9:04
Imran Adam9-Oct-07 9:04 
AnswerRe: ...(object sender, System.EventArgs e) Pin
Scott Dorman9-Oct-07 9:49
professionalScott Dorman9-Oct-07 9:49 
As Mark said, there is already a lot of information about this online.

Anyway, the sender parameter is an object representation of the control that caused the event to be sent. It is an object, which means that you need to have some knowledge of what the actual sender is supposed to be if you want to use it inside the event handler. In order to use the sender you need to cast it to the appropriate type. In the case of your example, you would need to do one of the following:
C#
private void Form1_Load(object sender, System.EventArgs e)
{
   Form f = sender as Form;
   if (f != null)
   {
      // do something here
   }
}
or
C#
private void Form1_Load(object sender, System.EventArgs e)
{
   Form f = (Form)sender;
   // do something here
}
To me, the preferred way is the first one since it is a bit safer.

The e parameter represents the "EventArgs" of the event. In reality, EventArgs is a class that is used to hold the data generated by the event that could be used within the event handler. All events should use either the System.EventArgs class or a custom (derived) System.EventArgs class. The default System.EventArgs class maintains no data about the event.


Scott.

—In just two days, tomorrow will be yesterday.

[Forum Guidelines] [Articles] [Blog]

GeneralRe: ...(object sender, System.EventArgs e) Pin
Imran Adam9-Oct-07 10:17
Imran Adam9-Oct-07 10:17 
GeneralRe: ...(object sender, System.EventArgs e) Pin
Scott Dorman9-Oct-07 10:27
professionalScott Dorman9-Oct-07 10:27 
QuestionDataGridView HeaderCell Painting Pin
cris34569-Oct-07 7:30
cris34569-Oct-07 7:30 
Questionsocket server disconnect Pin
gizmokaka9-Oct-07 7:25
gizmokaka9-Oct-07 7:25 
AnswerRe: socket server disconnect Pin
led mike9-Oct-07 7:54
led mike9-Oct-07 7:54 
GeneralRe: socket server disconnect Pin
gizmokaka9-Oct-07 8:09
gizmokaka9-Oct-07 8:09 
GeneralRe: socket server disconnect Pin
led mike9-Oct-07 8:29
led mike9-Oct-07 8:29 
Questionlabel text distorted in windows form Pin
sudhirkamath9-Oct-07 6:28
sudhirkamath9-Oct-07 6:28 
AnswerRe: label text distorted in windows form Pin
Juraj Borza9-Oct-07 9:44
Juraj Borza9-Oct-07 9:44 
GeneralRe: label text distorted in windows form Pin
Peter Vertes9-Oct-07 10:06
Peter Vertes9-Oct-07 10:06 
QuestionDatabase Backups Multi-Threading Pin
jikubhai9-Oct-07 5:37
jikubhai9-Oct-07 5:37 
AnswerRe: Database Backups Multi-Threading Pin
led mike9-Oct-07 6:00
led mike9-Oct-07 6:00 
GeneralRe: Database Backups Multi-Threading Pin
jikubhai9-Oct-07 19:15
jikubhai9-Oct-07 19:15 
GeneralRe: Database Backups Multi-Threading Pin
led mike10-Oct-07 4:40
led mike10-Oct-07 4:40 
QuestionSorting a ListView by more than one column Pin
scotlandc9-Oct-07 5:32
scotlandc9-Oct-07 5:32 
AnswerRe: Sorting a ListView by more than one column Pin
led mike9-Oct-07 6:05
led mike9-Oct-07 6:05 
AnswerRe: Sorting a ListView by more than one column Pin
Luc Pattyn9-Oct-07 6:10
sitebuilderLuc Pattyn9-Oct-07 6:10 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.