-
I have a user control which is supposed to act sort of like the Windows Taskbar. I have added a function to add and delete buttons (from an array) but I CAN'T GET THE F***ING THINK TO WORK.
Code:
Public Function AddButton(Optional strCaption As String)
Dim X As Long
X = cmdButton.Count + 1
Load cmdButton(X) 'Create instance (for instance, this button)
cmdButton(X).Left = 60 + X * (cmdButton(0).Width + 60)
cmdButton(X).Top = 60
cmdButton(X).Caption = strCaption
cmdButton(X).Width = cmdButton(0).Width 'Index 0 is main Button
cmdButton(X).Height = cmdButton(0).Height
cmdButton(X).Visible = True
End Function
That's how it adds the button. I call it from another form like so:
Code:
Private Sub Command1_Click()
UserControl1.AddButton "Hello"
MsgBox UserControl1.ButtonCount 'Property I added to see if the button was actually added to an array
End Sub
But instead of showing a new button, it just adds another one to the array, whereas if I did this:
Code:
Private Sub Command1_Click(Index As Integer)
'Creating instance of self
'Coordinates of main button: (0,0)
Load Command1(2)
Command1(2).Move 50, 50
End Sub
It works.
So, does anyone know why these buttons aren't showing up? Believe you me, I've tried everything, and yet the answer is probably so simple!
-
Yes, the answer depends probably on the first item in cmdbutton series. As you haven't specified it nobody will know what the problem is.
I tested using that function and it worked correctly, but i had to replace X with an static variable for manual counting, since it wont work in vb5