Export (0) Print
Expand All
1 out of 1 rated this helpful - Rate this topic

How to: Add 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.

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 the Handles keyword or the 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.

NoteNote:

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

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)
    
    Public Event PercentDone(ByVal Percent As Single, _
                             ByRef Cancel As Boolean)
    
Did you find this helpful?
(1500 characters remaining)
Thank you for your feedback

Community Additions

ADD
Show:
© 2014 Microsoft. All rights reserved.