Results 1 to 3 of 3

Thread: Accessing ImageList control from UserControl

  1. #1

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    Hi,
    I have been having problems with this for a while now. If you look at the common controls, you'll see that some of them (like the toolbar, for instance) can access the Imagelist control. You just need to specify which Imagelist control to access. How can i make my control do the same thing??

    ------------------
    r0ach(tm)

  2. #2
    Guru Aaron Young's Avatar
    Join Date
    Jun 1999
    Location
    Red Wing, MN, USA
    Posts
    2,177

    Post

    Here's a VERY basic example, it's a Listbox that will list the Keys of any Images in a specified ImageList Control.

    User Control: Add a Listbox and a Timer..
    Code:
    Public ImageList As String
    
    Private Sub Timer1_Timer()
        Dim iIndex As Integer
        Dim bFound As Boolean
        
        'See if a Value was Entered for the ImageList
        If Len(ImageList) Then
            'See if a Control by that Name Exists on the Form
            For Each Control In Parent.Controls
                If LCase(Control.Name) = LCase(ImageList) Then
                    bFound = True
                    Exit For
                End If
            Next
            If bFound Then
                'Make sure it IS an ImageList
                If TypeOf Parent.Controls(ImageList) Is MSComctlLib.ImageList Then
                    'Repopulate the List with the Keys of the Images in the ImageList
                    List1.Clear
                    With Parent.ImageList1.ListImages
                        For iIndex = 1 To .Count
                            List1.AddItem .Item(iIndex).Key
                        Next
                    End With
                End If
            Else
                If List1.ListCount Then List1.Clear
            End If
        Else
            If List1.ListCount Then List1.Clear
        End If
    End Sub
    
    Private Sub UserControl_Initialize()
        Timer1.Interval = 1000
        Width = List1.Width
        Height = List1.Height
    End Sub
    Add the Control to a Form and Set the ImageList Value to the Name of the ImageList Control you add toyour Form, then Add some Images to the ImageList with Values for the Keys and they'll be listed in the Listbox User Control.

    ------------------
    Aaron Young
    Analyst Programmer
    [email protected]
    [email protected]


  3. #3

    Thread Starter
    Fanatic Member r0ach's Avatar
    Join Date
    Dec 1999
    Location
    South Africa
    Posts
    722

    Post

    Great, thanx!!

    I tried it, and it didn't work!! It said Variable not defined:

    For Each Control In Parent.Controls
    If LCase(Control.Name) = LCase(ImageList) Then

    So, i just added "Dim Ctl as Control" and replaced Control (bold), and voila!

    Thanx a lot!!


    ------------------
    r0ach(tm)

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