'__________________________________________________ 'CREATING CONTROLS & EVENT HANDLERS AT RUNTIME '__________________________________________________ 'This shows how to adjust the form size, create a new button control, 'and create a click event handler for that new button. Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load '---set form size/position Me.Height = 200 Me.Width = 400 Me.Text = "Creating Controls and Events at Runtime" '---create a new button Dim btn As New Button btn.Location = New Point((Me.Width - btn.Width) / 2, (Me.Height - btn.Height) / 3) 'x & y btn.Text = "Click me!" '---now add an event handler to respond to when the button is clicked AddHandler btn.Click, AddressOf ButtonClickHandler '---add the control to the forms control collection Me.Controls.Add(btn) End Sub Private Sub ButtonClickHandler(ByVal sender As Object, ByVal e As EventArgs) Dim whichBtn As Button = CType(sender, Button) MsgBox("You clicked " + whichBtn.Text) End Sub End Class