July 2015
Intermediate to advanced
1300 pages
87h 27m
English
By default, when you declare a variable for an object that exposes events, Visual Basic cannot see those events. This is also the case with the previous section’s example, where you declare a Timer and then need to explicitly register for event handling. A solution to this scenario is to declare an object with the WithEvents keyword, which makes events visible to Visual Basic. Thanks to WithEvents, you do not need to register for events and can take advantage of the Handles clause to specify the event a method is going to handle. The code in Listing 15.2 demonstrates this, providing a revisited version of the EventsDemo class.
LISTING 15.2 Catching Events with WithEvents and Handles
Read now
Unlock full access