Adds a ListImage object to a ListImages collection.
Syntax
object.Add(index, key, picture)
The Add method syntax has these parts:
Part | Description |
object | Required. An object expression that evaluates to an object in the Applies To list. |
index | Optional. An integer specifying the position where you want to insert the ListImage. If no index is specified, the ListImage is added to the end of the ListImages collection. |
key | Optional. A unique string that identifies the ListImage object. Use this value to retrieve a specific ListImage object. An error occurs if the key is not unique. |
picture | Required. Specifies the picture to be added to the collection. |
Remarks
The ListImages collection is a 1-based collection.
You can load either bitmaps or icons into a ListImage object. To load a bitmap or icon, you can use the LoadPicture function, as follows:
Set imgX = ImageList1.ListImages.Add(,,LoadPicture("file name"))
You can also load a Picture object directly into the ListImage object. For example, this example loads a PictureBox control's picture into the ListImage object:
Set imgX = ImageList1.ListImages.Add(,,Picture1.Picture)
If no ListImage objects have been added to a ListImages collection, you can set the ImageHeight and ImageWidth properties before adding the first ListImage object. You can then add images of any size to the collection. However, when the ImageList control is bound to another Windows Common Control, all images you add to the collection will be displayed (in the bound Windows Common Control) at the size specified by the ImageHeight and ImageWidth properties. Once a ListImage object has been added to the collection, the ImageHeight and ImageWidth properties become read-only properties.
Note You can the use the ImageList control with any control by setting the Picture property of the second control to the Picture object of any image contained by the ImageList control. However, the size of the displayed image will not be affected by the ImageHeight and ImageWidth properties. In other words, the second control will display the image at its original size.
You should use the Key property to reference a ListImage object if you expect the value of the Index property to change. For example, if you allow users to add and delete their own images to the collection, the value of the Index property may change.
When a ListImage object is added to the collection, a reference to the newly created object is returned. You can use the reference to set other properties of the ListImage, as follows:
Dim imgX As ListImage
Dim I As Integer
Set imgX = ImageList1.ListImages. _
Add(,,LoadPicture("icons\comm\net01.ico"))
imgX.Key = "net connect" ' Use the new reference to assign Key.