?
Solved

C# Event handler guidelines

Posted on 2007-11-27
2
Medium Priority
?
371 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 2000 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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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…
It was really hard time for me to get the understanding of Delegates in C#. I went through many websites and articles but I found them very clumsy. After going through those sites, I noted down the points in a easy way so here I am sharing that unde…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…
Suggested Courses

752 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