What? You want to programmatically add a button to a VB.NET Windows.Forms Form/Panel/User Control and hook up an event handler? Heck, that's easy. Here we go. Start a new WindowsApplication and open up Form1 to the code view.

Paste in this:

Friend WithEvents cmdTemp As _
    System.Windows.Forms.Button = New Button

Private Sub cmdTemp_Click(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles cmdTemp.Click

    MsgBox("I've been clickified!!!")
End Sub

Private Sub Form1_Load(ByVal sender As System.Object, _
    ByVal e As System.EventArgs) Handles MyBase.Load

    Me.Controls.Add(Me.cmdTemp)
End Sub


Enjoy. For more form designerless goodness, make your canvas a PnlGridLayout. For ugly, generic UIs where you don't know what's coming ahead of time, using the Java-style GridLayout and adding things to the Form.Controls collection really is the way to go.

Even neater is when you hook up handlers with the AddHandler function, like this:

    Private Sub Form1_Load(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles MyBase.Load

        Me.Controls.Add(Me.cmdTemp)
        AddHandler cmdTemp.Click, AddressOf Me.genericButtonHandler
    End Sub

    Private Sub genericButtonHandler(ByVal sender As System.Object, _
        ByVal e As System.EventArgs)

        MsgBox("send all the button clicks you want here!")
    End Sub


You can use the AddHandler jive to hook that sub up to any button you make at any time, which is awfully useful stuff when creating buttons out of thin air.