17 Code to generate Button at Run-time in VB.NET

Code:

Public Class Form1
    Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load

    End Sub

    Sub AddButton(ByVal label As String)

        Dim b As Button

        b = New Button
        b.Location = New Point(53, 39)
        b.Text = label
        Me.Controls.Add(b)

    End Sub

    Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
        AddButton("A")
    End Sub
End Class








Output:  

Before Click:
After Click:

Previous
Next Post »