Sams Teach Yourself Visual Basic 6 in 24 Hours

Sams Teach Yourself Visual Basic 6 in 24 Hours

By Greg Perry

The Image List Control

As you know, a toolbar is a row of buttons with icons on them. The Toolbar control has one slight limitation: It cannot keep track of each image that you place on a toolbar button. Instead, the Toolbar control only works with a special control called an Image List control. Fortunately, the Image List control appears on the toolbox when you add the Microsoft Windows Common Controls 6.0 control set, as you did in the previous section.

Therefore, you might want to practice adding a toolbar to a Form window by opening a new project and then placing an Image List control on the Form window. Expand the Form window slightly so that the Form window is wide enough for a toolbar (approximately 6,645 twips wide).

The Image List control doesn't look like much. Just like the Timer control and the Common Dialog Box control, the Image List control's placed size and location don't matter much because the user will never directly see the Image List control on the form. The user will, instead, see images that the Image List control keeps track of. The Image List control works a lot like a graphic image array. The Image List control holds images from files, and when you're using it for toolbars, the Image List control holds toolbar icons such as the ones in Microsoft Visual Studio's \Program Files\Microsoft Visual Studio\Common\Graphics\Icons folder.

An image list is a list of images in an array-like control called the Image List control.

The easiest way to add images to the Image List control is by clicking the Image List control's Custom property to display Figure 19.3's custom property pages. This dialog box organizes the Image List control's figures and lets you manage each figure's properties separately.

19fig03.gif

Figure 19.3 Specifying Image List control properties in the Property Pages dialog box.

Click the Images tab to display the Images page. Here you will build a list of images that will ultimately end up on your application's toolbar. To add some images for this lesson's sample toolbar, click the Insert Picture button and select the icon file named Disk04 located in the \Program Files\Microsoft Visual Studio\Common\Graphics\Icons\Computer folder. The image will appear in the image list, and its index value will be set to 1, as Figure 19.4 shows.

19fig04.gif

Figure 19.4 The Image List control now has one image.

Keep inserting images in the following order (from the same folder to keep things simple): Key04, Mouse02, Trash01, and W95mbx01. As you insert the images one at a time, you'll notice that Visual Basic automatically updates the image's Index text box value. After you add the final image, your image list should look like Figure 19.5's list of icons.

19fig05.gif

Figure 19.5 The Image List control now contains five icon images.

Click OK to close the Property Pages dialog box and name the Image List control imlToolBar (using the Properties window) so the Toolbar control can reference the images you just stored in the Image List control.

Share ThisShare This

Informit Network