Private intCounter As Int16
Private intPos As Int16
Private Buttonclicked As Button
Private Sub Button_Click(ByVal sender As System.Object, ByVal e As System.EventArgs)
buttonClicked = CType(sender, Button)
' Tell the world what button was clicked
MessageBox.Show("You clicked " & Buttonclicked.Name)
End Sub
Private Sub addNewButton_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles addnewbutton.Click
intCounter += 1
intPos += 30
Dim newButton As Button
' Create the new control
newButton = New Button
' Set it up on the form
newButton.Location = New System.Drawing.Point(184, 16 + intPos)
newButton.Size = New System.Drawing.Size(75, 23)
newButton.Text = "Button" & intCounter
newButton.Tag = intCounter
newButton.Name = "Button" & intCounter
' Add it to the form's controls collection
Me.Controls.Add(newButton)
' Hook up the event handler
AddHandler newButton.Click, AddressOf Me.Button_Click
End Sub
Private Sub Deletenewbutton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Deletenewbutton.Click
Me.Deletenewbutton.Focus()
Me.Controls.Remove(Buttonclicked)
End Sub