What it means: Loaded + = MyWindow_Loaded;
This is the same as saying:
AddHandler Me.Loaded, AddressOf(MyWindow_Loaded)
Although in your code it can be part of a method declaration like this:
Private Sub MyWindowLoaded(ByVal sender As Object, ByVal e As EventArgs) Handles Me.Loaded
...
End Sub
In any case, this means that you are attaching a function named MyWindow_Loaded
to the event Loaded
.
source to share
While you can easily figure out what it is supposed to do, the syntax can be a little confusing. Making a padding between an event and a method doesn't really make sense, but the effect is of course related to the event handler.
The + = operator for an event attaches an event handler to the event. However, there is a shortcut that the compiler makes here to convert the method to a delegate. In fact, the generated code (which you can also use) looks something like this:
Loaded += new LoadedEventHandler(MyWindow_Loaded);
So what the code does is create an event handler delegate for the method and bind it to the event. The delegate type is determined by the event expected.
source to share