Click Here!
home account info subscribe login search My ITKnowledge FAQ/help site map contact us


 
Brief Full
 Advanced
      Search
 Search Tips
To access the contents, click the chapter and section titles.

Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98

Bookmark It

Search this book:
 
Previous Table of Contents Next


Using Images In Combo Boxes

We’ve seen in this book that you can add images to menus and to buttons. Can you add images to combo boxes? Yes, you can, using image combo boxes.

Image combo boxes are one of the Windows common controls, so you have to add those controls to your project. Here’s how you install image combo boxes step-by-step:

1.  Select the Project|Components menu item.
2.  Select the Controls tab in the Components box that opens.
3.  Click the Microsoft Windows Common Controls item in the Components box now, and click on OK to close the Components box, adding the common controls to the toolbox.
4.  Draw a new image combo box in your program.
5.  To store the images for the image combo box, you’ll need an image list control (another of the Windows common controls), so add one of those to your program as well by drawing it on your form (the control will not appear at runtime).
6.  Right-click the image list control now, and select Properties in the menu that appears in order to open the property pages, as shown in Figure 8.11.


Figure 8.11  The Images tab of the image list property pages.

7.  Click the Images tab in the image list’s property pages now, and use the Insert Picture button to insert all the images you want to use in the image list, as also shown in Figure 8.11 (where we’re using solid colors for each image).
8.  Close the image list property page by on clicking OK.
9.  Right-click the image combo control now and select the Properties item in the menu that opens.
10.  We need to connect the image list, ImageList1, to the image combo box, so click the General tab in the image combo property pages and select ImageList1 in the ImageList box, as shown in Figure 8.12.


Figure 8.12  The General tab of the image combo property pages.

11.  Close the image combo property pages by clicking on OK.
12.  Now add the items to the image combo, ImageCombo1, in code. To add those items to the image combo box, you actually add ComboItem objects to that control. To do that, you can use the image combo’s ComboItems collection’s Add method. This method takes the index of the item to add, a key (which is a unique text string that identifies the item), the caption of the item if any, and the index of the item’s picture in the associated image list control:
Private Sub Form_Load()
    ImageCombo1.ComboItems.Add 1, "key1", "Item 1", 1
    ImageCombo1.ComboItems.Add 2, "key2", "Item 2", 2
    ImageCombo1.ComboItems.Add 3, "key3", "Item 3", 3
End Sub

And that’s it. Now when you run the program, the combo box displays images, as shown in Figure 8.13. Now we’re using images in combo boxes.


Figure 8.13  A combo box displaying images.


Previous Table of Contents Next


Products |  Contact Us |  About Us |  Privacy  |  Ad Info  |  Home

Use of this site is subject to certain Terms & Conditions, Copyright © 1996-2000 EarthWeb Inc.
All rights reserved. Reproduction whole or in part in any form or medium without express written permission of EarthWeb is prohibited.