Apologies if this has been asked many times before, but I'm a fairly new VB.Net programmer, and I'm having a slight problem here with VB.Net

Without elaborating on my reasoning, I am adding controls to my form in code rather in designer mode. For example, buttons are added like this

' *** REST OF CODE IN HERE ***

Dim MyButton as New Button
MyButton.Location = New Point (100, 100)
MyButton.Size = New Size (64, 64)
MyButton.Text = "Click me to say Hello World"
Me.Controls.Add(MyButton)

' *** REST OF CODE IN HERE ***


rather than by the traditional way of "drawing" buttons on the form.

My question is, having done this, how do I write code to (say) display a message box to say "Hello World"?

What I mean is that, if I had drawn the button on using the designer, I would click on the button to generate a function within which I could enter code, e.g.

Private Sub MyButton_Click(etc.etc.) Handles MyButton.Click

MessageBox("Hello World!") ' or similar

End Sub


or similar. However, because I've created the button in code, VB.Net will not allow me to do this.

Anybody have any ideas? Any help would be greatly appreciated!!!!

Thanks again.