Using the WithEvents Statement

If you declare a variable using the WithEvents statement, the handlers for the events associated with the type of the variable can be generated by selecting the object in the class name list and the events in the method name list. Here's an example in case you're not familiar with the WithEvents statement.

Private WithEvents MyButton As Button

When the variable has been declared, the name will show up in the class name list. Based on the preceding code statement, MyButton will be in the method name list, and when you select MyButton, the method name list will include all the events associated with the Button type. By picking the Click event, for instance, the Click event handler will be generated.

You will still ...

Get Visual Basic® .NET Power Coding now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.