14.8. Implement a Custom Event Argument

Problem

When you raise an event, you need to pass an object that contains data related to the event that would be useful when handling it. For example, the MouseEventArgs class (used by the MouseDown event) includes the Button property, which indicates which mouse button was pressed.

Solution

Create a custom event argument class derived from the System.EventArgs class. When you raise the event, create an instance of your event argument class and pass it to the event handlers.

How It Works

When you declare your own event types, you will often want to pass event-specific state to any listening event handlers. To create a custom event argument class that complies with the Event pattern defined by the .NET ...

Get Visual Basic 2008 Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.