dynamic adding buttons

Koeneok
06-13-2002, 05:31 AM
Hello,
I want to add buttons (labels with actions) in runtime to my form. I use the following code, but it doesn't work well:

------
Private textboxs As New Collection

Private Sub Form_Load()
Dim lbl As Label
For i = 1 To 3
Set lbl = Controls.Add("vb.label", "naam" & i)
With lbl
.AutoSize = True
.Top = (i * 200)
.Caption = "see something"
.Visible = True
End With
textboxs.Add lbl
Next
End Sub

:( Private Sub textboxs_click(index As Integer)
MsgBox ("it works!!!")
End Sub
----------

I don't get the messagebox, but I want to make something like this.

Please help me.

ChiefRedBull
06-13-2002, 05:55 AM
You don't get the _Click event fired, because you've created a new label. It is not associated to textboxs at all. Sounds like you're trying to use a control array. Place one textbox onto your form, call it textboxs and set it Index property = 0. Now you can load new items like this:
Load textboxs(1)
textboxs.Top = 50
textboxs.Left = 50
textboxs.Visible = True
textboxs.Caption = "wooooo"

The events for the textboxs control will all have an extra parameter - ByVal Index As Integer - this is the index of the array member that is raising the event.

EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum