EVENTS
Properties let the application view and modify an object’s data. Methods let the program invoke the object’s behaviors and perform actions. Together, properties and methods let the program send information (data values or commands) to the object.
In a sense, events do the reverse: They let the object send information to the program. When something noteworthy occurs in an object’s code, the object can raise an event to tell the main program about it. The main program can then decide what to do about the event.
For example, the most commonly used event is probably a Button’s Click event. When the user presses and releases the mouse over a Button object, the object raises its Click event to tell the program that this has happened. Normally the program performs some action in response.
The following sections describe events. They explain how a class declares events and how other parts of the program can catch events.
Declaring Events
A class object can raise events whenever it needs to notify the program of changing circumstances. Normally, the class declares the event using the Event keyword. The following text shows the Event statement’s syntax:
[attribute_list] [accessibility] [Shadows] _
Event event_name([parameters]) [Implements interface.event]
The following sections describe the pieces of this declaration. Some of these are similar to earlier sections that describe constant, variable, and class declarations. By now, you should notice some similarity in the use of the ...
Get Visual Basic 2012 Programmer's Reference 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.