Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

load some CommandButtons dymanically to the form

Status
Not open for further replies.

ii128

Programmer
May 18, 2001
129
US
I need to load some CommandButtons dymanically to the form, and I want to do some functions when clicking on the CommonButtons.

How can I program that??

Here is some of my code:

Dim cmdDynamic() As CommandButton

ReDim cmdDynamic(10) As CommandButton
i=0
for i =0 to 10
Set cmdDynamic(i) = Controls.Add("VB.CommandButton", "RandomCmd" & i)
Next i

Then, How can I know when user clicks on the Button? Any events? or Methods? that will know the user clicks the Button.

 
'Add a command button to your form called cmdDynamic
'Set it's Index property to 0 (to allow an array)

Private Sub Form_Load()
Dim i
i = 0
For i = 1 To 9
Load cmdDynamic(i)
' Set some properties...
With cmdDynamic(i)
.Top = i * 500
.Left = 100
.Visible = True
.Caption = "cmdDynamic " & i
.Enabled = True
End With
Next i
End Sub

'And then just add your event handler

Private Sub cmdDynamic_Click(Index As Integer)
MsgBox "Button " & Index & " pressed"
End Sub
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top