Raising Events

You declare your own events by using the Event keyword. This keyword requires you to specify the event name and eventually a delegate signature. Although not mandatory (Event allows specifying no arguments), specifying a delegate signature is useful so that you can take advantage of AddHandler for subsequently intercepting events. The code in Listing 15.3 shows an alternative implementation of the Person class in which an event is raised each time the LastName property is modified.

LISTING 15.3 Implementing and Raising Events

Public Class Person    Public Event LastNameChanged(ByVal sender As Object,                                 ByVal e As EventArgs)    Public Property FirstName As String    Private ...

Get Visual Basic 2015 Unleashed now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.