Export (0) Print
Expand All
A
Expand Minimize

Visual Basic: Windows Controls

Visual Studio 6.0

Add Method (ListImages Collection)

See Also    Example    Applies To

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.

Note   When using the ImageList control on a DHTML Page designer, images cannot be added at design time. If you try to use the Add method in an uncompiled .dll project, you will get the run-time error: -2147418113 (8000ffff), "Method 'Add' of object images failed". However, the code will work when the .dll project is compiled.

Show:
© 2014 Microsoft