یه فرم درست کن، یه button روش بذار به اسم button1 که با کلیک روش بتونی button تولید کنی . بعد توی کد vb فرم همه چیزو پاک کن و کلا این رو paste کن.این کل کد:
Public Class Form1
Dim Index, _top, _left As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
createButton(Index)
Index = Index + 1
_top = _top + 22
_left = _left + 55
End Sub
Private Sub createButton(ByVal _nameind As Integer)
Try
Dim b As New Button
b.Name = "btn" & _nameind
b.Text = "دکمه " & _nameind
b.Top = _top
b.Left = _left
b.Width = 50
b.Height = 20
Me.Controls.Add(b)
AddHandler b.Click, AddressOf Btn_click
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
_top = 50
_left = 50
End Sub
Private Sub Btn_click(ByVal sender As Object, ByVal e As EventArgs)
Try
Dim btmp As Button
btmp = CType(sender, Button)
Select Case btmp.Name
Case "btn0"
Me.BackColor = Color.Green
Case "btn1"
Label1.Text = "This is my test"
Case "btn2"
btmp.BackColor = Color.Red
Case "btn3"
Me.Font = New Font("Tahoma", 11, FontStyle.Bold, GraphicsUnit.Pixel)
Case "btn4"
MsgBox("This is Test")
Case Else
MsgBox(btmp.Text)
End Select
Catch ex As Exception
MsgBox(ex.Message)
End Try
End Sub
End Class