Image Property (ActiveX Controls)

       

Returns or sets a value that specifies which ListImage object in an ImageList control to use with another object.

Syntax

object.Image [= index]

The Image property syntax has these parts:

Part Description
object An object expression that evaluates to an object in the Applies To list.
index An integer or unique string specifying the ListImage object to use with object. The integer is the value of the Index property; the string is the value of the Key property.

Remarks

Before setting the Image property, you must associate an ImageList control with a Toolbar, TreeView, or TabStrip control by setting each control's ImageList property to an ImageList control.

At design time, put an ImageList control on the form and load it with images, each of which is a ListImage object assigned an index number in a ListImages collection. On the General tab in the control's Property Pages dialog box, select the ImageList you want from the ImageList list box, such as ImageList1. For Tab and Button objects, you can also specify the image you want to associate with these objects by typing the index number of the specific ListImage object in the Image field on the Tabs or Buttons tab.

At run time, use code like the following to associate an ImageList to a control and then a ListImage to a specific object:

Set TabStrip1.ImageList=ImageList1
TabStrip1.Tabs(1).Image=2

Use the Key property to specify an ImageList control's ListImage object when you wish your code to be self-documenting, as follows:

' Assuming there is a ListImage object with the Key property value = 
' "close," use that image for a Toolbar button.
Toolbar1.Buttons(1).Image = "close"

' This is easier to read than just specifying an Index value, as below:
Toolbar1.Buttons(1).Image = 4 ' Requires that the ListImage object
' with Index property = 4 is the "close" image.

The value of the Index property of an object can change when objects in the collection are reordered, such as when you set the Sorted property to True. If you expect the Index property to change dynamically, it may be more useful to refer to objects in a collection by using the Key property.

If there are no images for a Tabs collection, the value of index is -1.