Dynamic Image List - July 2001
Dynamic Toolbar [Large, Small Icons, With and Without Text]

One of my pet peeves - once you assign an image list to a Toolbar, TreeView or ListView you can't change the images without 'unhooking' the Toolbar, TreeView or ListView. So the process is, unhook the image list from the control, change the images, re-hook the control. And try to remember the names or indexes of the images.

I have developed a technique which stores the images in an image control then dynamically builds the image list then hooks the images to the Toolbar. I demonstrate this as the July 2001 tip-of-the-month. The tip also demonstrates how to dynamically create a large and small icon tool bar.

Demo Program

I wrote a VB 6 program to demonstrate the tip. The demo uses the Microsoft Windows Common Controls 6.0 [mscomctl.ocx]. You could modify the code to use the VB 5 version. A screen shot of the demo:

Large Icons - With Text
Toolbar with large icons and button captions.
Back button is display the 'hot' image.

Small Icons - No Text
Small icons and no button captions.

Disabled Icons - No Text
Disabled icons and no button captions.

You can click the radio buttons to change the tool bar settings - large or small icons with or without text. Typically you would use a 'pop-up' menu to allow the user to select these items.

The demo uses two tool bars and one image list. Five more image lists are created dynamically. The image lists:

Image List Description
ImageList1(0) Normal Image - Large Icons
ImageList1(1) Disabled Image - Large Icons
ImageList1(2) Hot Image - Large Icons
ImageList1(3) Normal Image - Small Icons
ImageList1(4) Disabled Image - Small Icons
ImageList1(5) Hot Image - Small Icons

Store Images in the Application

The image list is created dynamically with images stored in image controls. In this example I put all the images in image controls on a picture box. The picture box's visibility is set to 'false'. You could put the images on another form or in a resource file or load them as files from the hard drive. The results would be the same. The picture box:

Images for Image Lists
Images - Zero thru 23.
Rows 1 to 4 and Columns 0 to 5.

The 'tag' property of the first image in the row is used as the image's key. For example: the first image [Image1(0)] has a tag of 'exit'.

The Demo Program Uses modConnectToWebSite

The demo program uses modConnectToWebSite.bas to display this page. For details on the use of that module click here.

Download VB 6 Source Code

Click here to download the VB 6 source code [10k]

Previous Tip   Tip Index    Next Tip


Updated 2001/08/01