Dim GenTop As Long
Dim lstimg As ImageList
Private Type itemX
Item As String
Icon As Long
Tooltip As String
End Type
Dim itemIndex As Long
Dim listItems() As itemX
Dim cachex() As itemX
Private Sub UserControl_Initialize()
lblList(0).Caption = UserControl.Name
GenTop = lblList(0).Top
End Sub
Private Sub UserControl_Resize()
On Error Resume Next
picBack.Height = UserControl.Height - 120
picBack.Width = UserControl.Width - 120
If vScroll.Visible = False Then
imgBack.Height = picBack.Height - 100
imgBack.Width = picBack.Width - 100
vScroll.Left = picBack.Width + 50
vScroll.Height = picBack.Height - 100
Else
vScroll.Left = picBack.Width - (vScroll.Width + 60)
imgBack.Height = picBack.Height - 100
imgBack.Width = vScroll.Left - imgBack.Left
vScroll.Height = picBack.Height - 80
End If
Call reSizeall
End Sub
Public Sub reSizeall()
For x = 0 To lblList.Count - 1
lblList(x).Width = imgBack.Width
Next
End Sub
Public Function Add(ByVal Item As String, Optional Icon As Long, Optional index As Long, Optional Tooltip As String)
itemIndex = itemIndex + 1
ReDim Preserve listItems(itemIndex)
If index = 0 Then
listItems(itemIndex).Item = Item
listItems(itemIndex).Icon = Icon
listItems(itemIndex).Tooltip = Tooltip
Else
End If
refresh
End Function
Private Function refresh()
ReDim cachex(UBound(listItems))
For x = 1 To UBound(listItems)
If listItems(x).Item <> "" Then
cachex(x).Item = listItems(x).Item
cachex(x).Icon = listItems(x).Icon
cachex(x).Tooltip = listItems(x).Tooltip
End If
Next
ReDim listItems(UBound(cachex))
For x = 1 To UBound(cachex)
If cachex(x).Item <> "" Then
listItems(x).Item = cachex(x).Item
listItems(x).Icon = cachex(x).Icon
listItems(x).Tooltip = cachex(x).Tooltip
End If
Next
For x = 1 To lblList.Count - 1
Unload lblList(x)
Unload imgList(x)
Next
lblList(0).Caption = ""
Set imgList(0).Picture = Nothing
For x = 1 To UBound(listItems)
'text here
If x - 1 <> 0 Then
Load lblList(x - 1)
Load imgList(x - 1)
lblList(x - 1).Top = imgList(x - 2).Top + 270
imgList(x - 1).Top = imgList(x - 2).Top + 270
Else
lblList(x - 1).Top = GenTop
imgList(x - 1).Top = GenTop
End If
lblList(x - 1).Caption = listItems(x).Item
'icon here
If lstimages Then
If lstimg.ListImages.Count > 0 Then
If Icon > 0 Then imgList(x - 1).Picture = lstimg.ListImages.Item(Icon).Picture
End If
End If
'tooltip here
lblList(x - 1).ToolTipText = listItems(x).Tooltip
lblList(x - 1).Visible = True
imgList(x - 1).Visible = True
Next
'whether visible or not we should give this thing its value to avoid problems ama?
For x = 0 To lblList.Count - 1
If lblList(x).Top + lblList(x).Height > picBack.Height Then
If (lblList.Count - 1) - x > 0 Then
vScroll.Max = (lblList.Count - 1) - x
Else
vScroll.Max = 1
End If
Exit For
End If
Next
'activates scrollbar
If lblList(lblList.Count - 1).Top + lblList(lblList.Count - 1).Height > picBack.Height Or lblList(0).Top < 90 Then
vScroll.Visible = True
UserControl_Resize
Else
vScroll.Visible = False
UserControl_Resize
End If
End Function
Public Function Clear()
ReDim listItems(0)
itemIndex = 0
refresh
End Function
Public Function removeItem(ByVal index As Long)
listItems.Item = ""
listItems.Icon = 0
listItems.Tooltip = ""
refresh
End Function
Private Sub vScroll_Change()
GenTop = 90 + (0 - (vScroll.Value * 270))
refresh
End Sub