Results 1 to 2 of 2

Thread: User Control not working!

  1. #1
    Guest

    Angry

    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!

  2. #2
    transcendental analytic kedaman's Avatar
    Join Date
    Mar 2000
    Location
    0x002F2EA8
    Posts
    7,221
    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
    Use
    writing software in C++ is like driving rivets into steel beam with a toothpick.
    writing haskell makes your life easier:
    reverse (p (6*9)) where p x|x==0=""|True=chr (48+z): p y where (y,z)=divMod x 13
    To throw away OOP for low level languages is myopia, to keep OOP is hyperopia. To throw away OOP for a high level language is insight.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width