VB.Net add new button & add it's click event at runtime

By James J

How to add new button at runtime & add it's click event at runtime...

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
        Dim MyButton As New Button()

'Set the button properties...
        
With MyButton
             .
Location = New Point(12, 12)
             .
Size = New Size(75, 30)
             .
TabIndex = 0
            .
Text = "Click Me"
        
End With
      
Controls.Add(MyButton)

        
AddHandler MyButton.Click, AddressOf MyButton_Click
End Sub


Private Sub MyButton_Click(ByVal obj As Object, ByVal e As EventArgs)
        MessageBox.
Show("New Added Button Click Event")
End Sub

VB.Net add new button & add it's click event at runtime  (2827 Views)