共用方式為


How to: Raise an Event (Visual Basic) 

This example defines an event (TimeExpired) and uses the RaiseEvent statement to cause the event to occur.

Example

Public Event TimeExpired(ByVal Status As String)
Public Sub RaiseTimeExpiredEvent()
    RaiseEvent TimeExpired("Your time has run out")
End Sub

This code example is also available as an IntelliSense code snippet. In the code snippet picker, it is located in Visual Basic Language. For more information, see How to: Insert Snippets Into Your Code (Visual Basic).

Compiling the Code

This example requires:

  • Access to the members of the System namespace. Add an Imports statement if you are not fully qualifying member names in your code. For more information, see Imports Statement.

  • The Event statement to be at class level and not inside any procedure.

  • The RaiseEvent statement to be inside some procedure in your application.

See Also

Tasks

How to: Create an Event and Handler (Visual Basic)

Reference

Event Statement
RaiseEvent Statement

Concepts

Events and Event Handlers

Other Resources

Events in Visual Basic