SyntaxHandles name.event
DescriptionThe Handles statement defines a procedure as the event handler for a particular class or type event. Usage at a Glance
ExampleIf you add a command button to a new form, the form initialization code generated by Visual Studio includes the following statement: Friend WithEvents Button1 As System.Windows.Forms.Button The WithEvents keyword allows the events of this control to be processed by event handlers. The default procedure template used to handle this button's Click event looks like the following: Private Sub Button1_Click(ByVal sender As System.Object, _ ByVal e As System.EventArgs) Handles Button1.Click ' ----- Custom code goes here. End Sub The Handles clause in this code is what links Button1's Click event with the event handler code. Version Differences
See AlsoWithEvents Keyword |