Image List Component

The ImageList component is not a control as such, but it is a component that allows you to organize groups of images. Although it has no visual representation itself, it can supply images to other controls, such as ListView, or serve as a repository for images to be loaded into a picture box. You can set the size and color depth for the images and iterate through them as you would a collection. Table 3-15 shows important properties of the ImageList component.

Table 3-16 Important Properties of the ImageList Component

Property Description

ColorDepth Sets the color depth for the images contained in the ImageList component.

Images The collection of images organized by the ImageList component.

ImageSize Sets the size for the images contained in the ImageList control.

You can add new items to the ImageList control by clicking the Images property in the Properties window. This opens the Images Collection Editor, as shown in Figure 3-11.

Figure 3-11 The Image Collection Editor

The Images Collection Editor images can be added, removed, or their order in the collection changed via the Images Collection editor. Once images have been added to the ImageList component, you can set the color depth for each image by setting the

ColorDepth property, and you can set all of the images to a specified size by setting the ImageSize property.

At run time, you can access the images contained in the ImageList component via the Images collection, as shown in the following example:

PictureBoxl.Image = ImageListl.Images(O) // C#

pictureBoxl.Image = imageList1.Images[0];

ImageList components can be used to provide images to other controls in your user interface. Several controls, such as Button, CheckBox, RadioButton, and others, host ImageList, ImageKey, and ImageIndex properties. You can provide images from an ImageList component to these controls by setting these properties.

► To provide an image to a control from an ImageList component

1. Set the ImageList property of the control to the ImageList component that hosts the image you want to provide.

2. Set either the ImageIndex property or the ImageKey property to the appropriate image in the ImageList.

Was this article helpful?

0 0

Post a comment