Click to See Complete Forum and Search --> : Accessing ImageList control from UserControl
r0ach
Jan 13th, 2000, 08:48 PM
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)
Aaron Young
Jan 13th, 2000, 10:21 PM
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..
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
aarony@redwingsoftware.com
ajyoung@pressenter.com
r0ach
Jan 14th, 2000, 11:39 AM
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)
vbforums.com
Copyright Internet.com Inc., All Rights Reserved.