[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

C# Event handler guidelines

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

New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

Question has a verified solution.

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

A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
In real business world data are crucial and sometimes data are shared among different information systems. Hence, an agreeable file transfer protocol need to be established.
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Please read the paragraph below before following the instructions in the video — there are important caveats in the paragraph that I did not mention in the video. If your PaperPort 12 or PaperPort 14 is failing to start, or crashing, or hanging, …
Suggested Courses

873 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