Solved

C# Event handler guidelines

Posted on 2007-11-27
2
361 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
  • 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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
This tutorial demonstrates a quick way of adding group price to multiple Magento products.

747 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now