ImlListImages class

The collection of the pictures of an ImageList, which its ListImages property returns. Its items are ImlListImage objects, numbered from 1, and an item can have a key as well.

Dim Image As ImlListImage
ImageList1.ListImages.Add , "open", ColorSquare(vbRed)
ImageList1.ListImages.Add , "save", ColorSquare(vbBlue)
ImageList1.ListImages.Add 1, "new", ColorSquare(vbGreen)       ' before the first
For Each Image In ImageList1.ListImages
    Debug.Print Image.Index; Image.Key
Next
' Output:
'  1 new
'  2 open
'  3 save

ColorSquare in the samples of this page is a function of the program’s own that returns a bitmap of one color, 16 pixels wide and high.

A program goes through the pictures with For Each, or by number from 1 to Count. It cannot make an ImlListImages object with New.

Numbers and keys

The number of a picture is its place in the list. It changes when a picture is added before it or removed before it, so a program that keeps a number over such a change keeps the wrong picture. A key stays with its picture.

A key is any string, and capital and small letters in it are the same: "Open" and "OPEN" are one key. No two pictures of a list have the same key. A picture needs no key: an empty string is no key, and any number of pictures can be without one.

ImageList1.ListImages.Add , "open", ColorSquare(vbRed)
ImageList1.ListImages.Add , "save", ColorSquare(vbBlue)
Debug.Print ImageList1.ListImages("SAVE").Index
ImageList1.ListImages.Remove "open"
Debug.Print ImageList1.ListImages("save").Index
Debug.Print ImageList1.ListImages.Exists("open")
' Output:
'  2
'  1
' False

Properties

Count

The number of pictures in the list. Long, read-only.

Item

Returns one picture. It is the default member, so ImageList1.ListImages("open") is ImageList1.ListImages.Item("open").

Syntax: object.Item( Index ) As ImlListImage

Index
required The number of the picture, from 1 to Count, or its key as a String.

A number outside that range raises run-time error 9, and a key that no picture has raises run-time error 5. Exists asks without an error.

Methods

Add

Puts a picture into the list and returns its ImlListImage.

Syntax: object.Add( [ Index ] [, Key ] [, Picture ] ) As ImlListImage

Index
optional A Long: the number the new picture gets. The pictures from that number on move up by one. Without it, or with 0, the picture goes after the last one.
Key
optional A String by which the program can name the picture. See Numbers and keys.
Picture
An icon or a bitmap, as a picture object. The declaration marks it optional, and the method cannot do without it.

A call without a picture, with Nothing or with an empty picture, such as LoadPicture("") returns, raises run-time error 35607, Required argument is missing. A negative Index, and one greater than Count + 1, raises run-time error 35600, Index out of bounds. A Key that another picture has raises run-time error 457.

The first picture added sets the size of the list, and what the list does with a bitmap of another size and with a bitmap’s mask color is under Filling the list and Transparent parts.

Clear

Removes every picture. The list is then as new: its ImageWidth and ImageHeight are 0, and a control that shows the list must be given it again once it has pictures.

Syntax: object.Clear

Exists

Returns whether the list has a picture of a number or a key, so that a program can ask before Item raises an error.

Syntax: object.Exists( Index ) As Boolean

Index
required The number or the key to look for.

Remove

Removes one picture. The pictures after it move down by one.

Syntax: object.Remove Index

Index
required The number or the key of the picture. One that the list does not have raises the error that Item raises for it.

Removing the only picture left leaves the list as Clear does.

See Also