Say I have an object that I dynamically create. For example, say I create a button called \"MyButton\":
Dim MyButton as New Button()
MyButton.Name = \"MyButt
With the newer versions of VB.NET you can use a lambda expression inline instead of an entire method (if you want)
Dim MyButton as New Button()
MyButton.Name = "MyButton"
AddHandler MyButton.Click, Sub(sender2, eventargs2)
'code to do stuff
'more code to do stuff
End Sub
You use AddHandler
and AddressOf
like this:
Dim MyButton as New Button()
MyButton.Name = "MyButton"
AddHandler MyButton.Click, AddressOf MyButton_Click
There is more info here in the MSDN documentation: