U picture box u design timeu stavis jedan command button i nazoves ga, na primer, cmdButton, stavis index property na 0, a Visible na false.
Code:
Private Sub cmdButton_Click(Index As Integer)
Debug.Print cmdButton(Index).Tag
End Sub
Private Sub Command2_Click()
Static Counter As Integer
Counter = Counter + 1
AddButton "Button" & Counter, "Button" & Counter
End Sub
Public Function AddButton(BtnCaption As String, BtnTag As String)
Dim Ind As Integer
Ind = cmdButton.ubound
Load cmdButton(Ind + 1)
cmdButton(Ind + 1).Move cmdButton(Ind).Left + cmdButton(Ind).Width + 30, cmdButton(Ind).Top
cmdButton(Ind + 1).Tag = BtnTag
cmdButton(Ind + 1).Caption = BtnCaption
cmdButton(Ind + 1).Visible = True
End Function
Dugmici ne moraju da se zovu razlicito. Na primer, po Tag propertyju mozes da ih razlikujes.
Za sirinu texta pogledaj textWidth metod pictureboxa