Solved

C# Event handler guidelines

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

Increase Agility with Enabled Toolchains

Connect your existing build, deployment, management, monitoring, and collaboration platforms. From Puppet to Chef, HipChat to Slack, ServiceNow to JIRA, Splunk to New Relic and beyond, hand off data between systems to engage the right people.

Connect with xMatters.

Question has a verified solution.

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

We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
Wouldn’t it be nice if you could test whether an element is contained in an array by using a Contains method just like the one available on List objects? Wouldn’t it be good if you could write code like this? (CODE) In .NET 3.5, this is possible…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this brief tutorial Pawel from AdRem Software explains how you can quickly find out which services are running on your network, or what are the IP addresses of servers responsible for each service. Software used is freeware NetCrunch Tools (https…

717 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