Solved

C# Event handler guidelines

Posted on 2007-11-27
2
366 Views
Last Modified: 2013-12-16
Is it usual to use the sender object in the event handler or should the object be contained in the event argument? I.e.

event EventHandler<MyControlEventArgs > MyControlChangedState;

void OnMyControlChangedState( MyControl myControl )
        {
            if ( MyControlChangedState != null )
            {
                MyControlChangedState( myControl, new MyControlEventArgs()  );

                // Or have the myControl object in event args
                // MyControlChangedState( myControl, new MyControlEventArgs( myControl )  );
            }
        }

void myControl_StateChanged( object sender, MyControlEventArgs e )
{
   // Get my control from sender or get it from the event args?
}
0
Comment
Question by:gromul
[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
  • 2
2 Comments
 
LVL 55

Expert Comment

by:Jaime Olivares
ID: 20361237
the sender should be enough
0
 
LVL 55

Accepted Solution

by:
Jaime Olivares earned 500 total points
ID: 20361247
of course, if you are developing your own event and you call without specifiying the proper sender, it will fail. But the Microsoft's model suggest to use the sender.
0

Featured Post

Major Incident Management Communications

Major incidents and IT service outages cost companies millions. Often the solution to minimizing damage is automated communication. Find out more in our Major Incident Management Communications infographic.

Question has a verified solution.

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

Suggested Solutions

More often than not, we developers are confronted with a need: a need to make some kind of magic happen via code. Whether it is for a client, for the boss, or for our own personal projects, the need must be satisfied. Most of the time, the Framework…
Entity Framework is a powerful tool to help you interact with the DataBase but still doesn't help much when we have a Stored Procedure that returns more than one resultset. The solution takes some of out-of-the-box thinking; read on!
I've attached the XLSM Excel spreadsheet I used in the video and also text files containing the macros used below. https://filedb.experts-exchange.com/incoming/2017/03_w12/1151775/Permutations.txt https://filedb.experts-exchange.com/incoming/201…

742 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