The ImageList Control

ImageList controls work behind the scenes in the Toolbar, ListView, TreeView, StatusBar, and TabStrip controls. The Visual Basic control that implements the ImageList concept is specifically designed to work with its partner controls. But if you look closely at ImageLists, you’ll see that they also have a wider potential. Unfortunately, the control doesn’t provide built-in features for some of the things you might like to do with it. Fortunately, it does provide a handle to the underlying control, and a Hardcore programmer with a handle knows no ­limits.

An ImageList is a collection of images of the same size and type, but they’re more than just images. When you insert an image into the list, the control gives it a mask. If the image is an icon, its internal mask is reused. If it is a bitmap or a metafile, a mask is created, probably using a technique similar to the one used for CPictureGlass (see “Animating Pictures,” in Chapter 7). The end result is a collection of icons of the same size. When you attach an ImageList to another control, you don’t need to worry about what gets drawn and how, but you’ll understand the process better if you experiment with the methods of an unattached ImageList.

The Test ImageList program (TIMAGE.VBP), shown in Figure 11-13, illustrates operations you can perform directly with ImageList controls. The images on the

Figure 11-13. Drawing with ImageLists.

right side of the form represent the images in lists of icons and bitmaps, respectively. The bitmap on the left provides a background to demonstrate how images can be drawn in different ways. To see how the different operations work on a solid background, use the Picture check box to turn the picture off.
You can experiment with this program to understand the fundamental difference between icons and bitmaps and how you can handle each correctly in ImageLists.

Check out the splitter bars on the Meriwether program. Hardcore readers Vadim Katsman and Elliot Witticar took up my challenge and suggested several enhancements to the original horizontal and vertical splitter classes provided with the first edition. I’m not going to say any more about splitters except that you’ll see enhanced splitter classes on the companion CD. You can find lots of ways to use splitters. You might start by giving Edwina two resizable editing windows (like those in the Visual Basic editor).

Figure 11-14 shows a map of ImageList methods and properties. ImageLists provide four ways of placing images on a surface: the Picture property, the ExtractIcon method, the Overlay method, and the Draw method. Two ­pro­-
perties, BackColor and MaskColor, affect the operations of the four drawing mechanisms.

Figure 11-14. An ImageList map.