# TImageList

TImageList is a component that provides a list of images that can be used within other components like TToolBar of TActionList.

## Example with ComboBox

To use TImageList, drop an TImageList object onto the form. In this example we need six images.

All images must be the same size. If two sizes of image are to be used, then two TImageLists must be used.

Set the height and width of the images in the Object Inspector; In this case 50px wide by 18px high.

Set Style to csOwnerDrawFixed.

Double-click on the TImageList icon to open the TImageList editor. Make sure that the icons show correctly when selected. If they are smaller than expected, check the size in the Object Inspector <F11>. You may have to reload the images.

Place a ComboBox on the form and name it cbSymbols.

In the FormCreate event enter:

 cbSymbols.Items.Clear;
for I := 0 to 5 do
cbSymbols.ItemIndex := 0;

This will write 6 blank entries, and select the first.

In the OnDrawItem event for cbSymbols place the following code:

procedure TMyForm.cbSymbolsDrawItem(
aControl: TWinControl;
iIndex: Integer;
aRect: TRect;
aState: TOwnerDrawState );
var
cnv: TCanvas;
begin
if not (aControl is TComboBox) then exit;
cnv := TComboBox( aControl ).Canvas;
Imagelist1.Draw( cnv, aRect.Left+2, aRect.Top+2, iIndex );
end;

The adjustments (+2) are to center the image in the item, if necessary.

## Example with SpeedButton

Add images to the ImageBox like in the previous example and use:

   SpeedButton1.GetBitmap(iIndex,spbTCNext.Glyph);