May 2010
Intermediate to advanced
1272 pages
61h 18m
English
WithEvents KeywordBy default, when you declare a variable for an object that exposes events, Visual Basic cannot see those events. This is also the case of 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 that makes events visible to Visual Basic. Thanks to WithEvents, you do not need to register for events, and you can take advantage of the Handles clause to specify what 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
Notice that ...
Read now
Unlock full access