Aracılığıyla paylaş


Custom Event Handler Design

If you are not using the generic EventHandler<TEventArgs> delegate, the following guidelines help you design event handlers correctly.

Do use a return type of System.Void for event handlers.

An event handler can invoke multiple methods but there is no way to receive multiple return values from an event handler. By making the method return Void, you eliminate the possibility of lost return value data.

Do set the type of the first parameter of the handler as Object and call it sender.

Do set the type of the second argument to the handler as either System.EventArgs or a derived class. The parameter should be called e.

Do not have more than two parameters on event handlers.

Portions Copyright 2005 Microsoft Corporation. All rights reserved.

Portions Copyright Addison-Wesley Corporation. All rights reserved.

For more information on design guidelines, see the "Framework Design Guidelines: Conventions, Idioms, and Patterns for Reusable .NET Libraries" book by Krzysztof Cwalina and Brad Abrams, published by Addison-Wesley, 2005.

See Also

Concepts

Event Design

Other Resources

Member Design Guidelines

Design Guidelines for Developing Class Libraries