Reputation: 89
I got my first progamming experience at Visual Basic 6.0. So now, I use Visual Basic 2015. And I See some Different at the Code. In Visual Basic 2015
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
So in VB 6.0 I didn't found such a code like "Handles MyBase.Load
", what does Handles
mean and what is it do?
Upvotes: 1
Views: 6331
Reputation: 6175
From a VB6 perspective, it allows you to name your event handler procedure whatever you want. In VB6, you are required to have the format MyControl_someEvent
, where MyControl
is the name of the control and someEvent
is the name of the event being handled. In VB.Net, you can call your event whatever you want. For example, the code you have above:
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Could be written thus:
Private Sub HowAboutThemCUBS(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
And it would still fire when the MyBase.Load event got triggered.
You should read the links that the other responders have posted, too. There is more that you ought to know about the differences than just this (for example, this structure allows you to have a single handler that handles more than one type of event, which you couldn't do in VB6).
Upvotes: 2
Reputation: 159
Try reading the documentation for Handles it has a good explination about them:
msdn.microsoft.com/en-us/library/6k46st1y.aspx
Upvotes: 0
Reputation: 2750
Handles will listen for the events that follow eg. MyBase.Load
, and when one of those events happens, the method will run
Upvotes: 1