# ImlListImage class
{: .no_toc }

One picture of an [**ImageList**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md): its number, its key, the picture it was made from, and the methods that draw it and return it as an icon. A program gets one from the [**ImlListImages**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/ImlListImages.md) collection, and from that collection's [**Add**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/ImlListImages.md#add) method.

```tb check_build check_run arch=win32,win64
Dim Image As ImlListImage
Set Image = ImageList1.ListImages.Add(, "open", ColorSquare(vbRed))
Image.Tag = "Opens a file"
Debug.Print Image.Index; Image.Key
Debug.Print ImageList1.ListImages("open").Tag
Debug.Print Image.Picture.Type = vbPicTypeBitmap
Debug.Print Image.ExtractIcon.Type = vbPicTypeIcon
' Output:
'  1 open
' Opens a file
' True
' True
```

**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 cannot make an **ImlListImage** object with **New**. An object kept in a variable after its picture is removed from the list, or after the list is cleared, still has its number, and its [**Draw**](#draw) and [**ExtractIcon**](#extracticon) then work on the picture that has that number, if there is one.

* TOC
{:toc}

Properties
----------

### Index
{: .no_toc }

The number of the picture in the list, from 1. **Long**, read-only. It changes when a picture is added or removed before this one.

### Key
{: .no_toc }

The key of the picture in the [**ImlListImages**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/ImlListImages.md) collection. **String**. Empty for a picture without a key.

An assignment gives the picture another key, and the collection no longer finds it by the old one. An empty string takes the key away. A key that another picture of the list has raises run-time error 457, and the picture keeps its key.

```tb check_build check_run arch=win32,win64
ImageList1.ListImages.Add , "open", ColorSquare(vbRed)
ImageList1.ListImages.Add , "save", ColorSquare(vbBlue)
ImageList1.ListImages("open").Key = "load"
Debug.Print ImageList1.ListImages.Exists("open"); ImageList1.ListImages("load").Index
On Error Resume Next
ImageList1.ListImages("load").Key = "save"
Debug.Print Err.Number; ImageList1.ListImages(1).Key
' Output:
' False 1
'  457 load
```

### Picture
{: .no_toc }

The picture object that was given to [**Add**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/ImlListImages.md#add). The list keeps a copy of its own, of the list's size and with the transparent parts made at the addition, and [**Draw**](#draw) and [**ExtractIcon**](#extracticon) work on that copy.

The property is read-only: an assignment raises run-time error 383. A program that wants another picture in this place removes the item and adds one at the same number.

### Tag
{: .no_toc }

A value of the program's own, which the list does not use. **Variant**: unlike the [**Tag**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/Common.md#tag) of a control it holds a value of any type, an object included, which is assigned with **Set**.

A new picture has an empty string.

Methods
-------

### Draw
{: .no_toc }

Draws the picture on a device context.

Syntax: *object*.**Draw** *hDC* [, *X* ] [, *Y* ] [, *Style* ]

*hDC*
: *required* A **LongPtr**: the handle of the device context, such as the **hDC** of a form or a picture box.

*X*, *Y*
: *optional* **Long**: where the top left corner of the picture goes, in pixels of the device context. The default is 0 for each.

*Style*
: *optional* How the picture is drawn: a member of [**ImlDrawConstants**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md#imldrawconstants), or the sum of several. Without it the picture is drawn as **ImlDrawNormal** draws it.

```tb check_build
ImageList1.ListImages.Add , "open", ColorSquare(vbRed)
' On the form that the image list is on, 8 pixels from its top left corner.
ImageList1.ListImages("open").Draw ImageList1.Parent.hDC, 8, 8, ImlDrawTransparent
```

The transparent parts of the picture leave the device context as it is, unless the list's [**UseBackColor**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md#usebackcolor) is **True**: then they are filled with its [**BackColor**](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md#backcolor), except with **ImlDrawTransparent**. With **ImlDrawNoMask** and **UseBackColor** **False**, the pixels of a bitmap that had the mask color are drawn black.

### ExtractIcon
{: .no_toc }

Returns the picture as a new icon of the list's size, with the picture's transparent parts. The icon is the program's: it does not change when the list does.

Syntax: *object*.**ExtractIcon**( ) **As IPictureDisp**

## See Also

- [ImageList](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md) class
- [ImlListImages](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/ImlListImages.md) class -- the collection of the pictures
- [ImlDrawConstants](/twinBASIC-docs/tB/Packages/Contributed/VBCCR18/ImageList/index.md#imldrawconstants) -- the values of the *Style* argument of **Draw**
