Export (0) Print
Expand All

Adding Events to a Class

You add events to a class by declaring them with the Events statement. The declaration includes the name of the event and the arguments it uses.

To add an event to a class

  • In the Declarations section of the class module that defines the class, use the Event statement to declare the event with whatever arguments you want it to have. For example:
    Public Event PercentDone(ByVal Percent As Single, _
       ByRef Cancel As Boolean)
    

Events cannot have return values, optional arguments, or ParamArray arguments.

Adding an event to a class specifies that an object of this class can raise a specific event. To cause an event to actually happen, you must use the RaiseEvent statement. You can use Handles keyword or AddHandler statement to associate the event with an event handler procedure. Events must be raised within the scope where they are declared. For example, a derived class cannot raise events inherited from a base class.

See Also

Walkthrough: Declaring and Raising Events | Walkthrough: Handling Events | Events and Event Handlers | Delegates and the AddressOf Operator | AddHandler and RemoveHandler | Writing Event Handlers | Polymorphism | RaiseEvent Statement | Handles | AddHandler Statement

Show:
© 2015 Microsoft