Index | Next 

Event handlers

In VB6 a method that handles an event must follow the object_eventname naming convention. In VB.NET event handlers can have any name, provided that they are marked with an opportune Handles clause:
        Private Sub NameClickHandler(ByVal sender As Object, ByVal e As EventArgs) _
            Handles txtName.Click
            ' handle click events originating from the txtName control
            ' ...
        End Sub
Notice that the Handles clause for events raised by the form itself must reference the MyBase object:
        Private Sub FormClickHandler(ByVal sender As Object, ByVal e As EventArgs) _
            Handles MyBase.Click
            ' handle click events originating from the current form
            ' ...
        End Sub

 

Index | Next