Let's see an example; this one is named Events on the CD-ROM. In this case, I'll create a custom event that occurs when you click a button three times, called ThreeClick. To keep track of how many times the button has been clicked, I'll use an object called tracker, of a class I'll call ClickTrack:

Public Class ClickTrack
⋮
End Class

To implement the ThreeClick event, I use the Event statement, indicating that the event handler for this event should be passed one argument, a string holding a message (which will just indicate that the event occurred):

Public Class ClickTrack
Public Event ThreeClick(ByVal Message As String)⋮
End Class

How can we make this event actually occur? You just use the RaiseEvent method. In this case, you must pass RaiseEvent a message you want to associate with this event (if you had given ThreeClick two arguments, you'd have to pass RaiseEvent two arguments, and so on). I can keep track of the number of button clicks with a Sub procedure named Click and raise the ThreeClick event when three clicks have occurred, passing that event's handler the string "You clicked three times":

That's how you make a custom event occur—with RaiseEvent. I'll need an object of this new ClickTrack class, and I'll call that object tracker. Note that I declare it using the keyword WithEvents to indicate this new object can handle events:

Dim WithEvents tracker As New ClickTrack()

Now that we've created a new event, you also can write an event handler for it, just make sure you accept the right number of type of arguments and use a Handles clause to indicate what event you're handling (which is tracker.ThreeClick in this case); when the event occurs, I'll display the message we've associated with the event in a text box: