HOWTO: Add Images to the CE ImageList Control

ID: Q187962


The information in this article applies to:
  • Microsoft Windows CE Toolkit for Visual Basic 6.0
  • Microsoft Windows CE Toolkit for Visual Basic 5.0


SUMMARY

The Microsoft CE ImageList Control allows a Visual Basic developer to store images in an ImageList and to give other controls, such as the TreeView, ListView and TabStrip controls, a way to refer to that collection of images.

This article demonstrates how to add images to the ImageList control.


MORE INFORMATION

The ImageList Control is significantly different from the standard Win32 Visual Basic ImageList control, having been optimized for size and speed for the Windows CE operating system. For this version of the ImageList control:

  • Images can only be added at run time.


  • Images can be .bmp, .dib, or .2bp format.


  • There is no ListImage object or ListImages collection.


  • The Add method takes a file name rather than using LoadPicture.


The following sample shows how to use the Add method and the hImageList property to add images to the ImageList control and use it with the ListView control.

Step-by-Step Example

  1. Start a new Windows CE (HPC) project in Visual Basic. Form1 is created by default.

    Perform steps 2 through 4 with the Windows CE Toolkit for Visual Basic 5.0 only.


  2. From the Windows CE menu, click Control Manager.


  3. Select the ImageListCtrl Class, and install it in Emulation by selecting Emulation from the Install menu. You should receive confirmation that the registration succeeded.


  4. Repeat step 3 for ListViewCtrl Class.

    NOTE: Failing to install and register the ImageList and ListView controls properly in the emulator will result in a startup error in the application at run-time. For additional information on how to use the Control Manager, please see the following article in the Microsoft Knowledge Base:

    Q185204 HOWTO: Use the Control Manager in CE Toolkit for Visual Basic


  5. Select Components from the Project menu, select both the Microsoft CE ImageList Control and Microsoft CE ListView Control.


  6. Place an ImageList control (ImageList1) and a ListView control (ListViewCtrl1) on Form1.


  7. Place two CommandButtons named cmdLeftArrow and cmdRightArrow on Form1.


  8. Change the captions of cmdLeftArrow and cmdRightArrow to "Left Arrow" and "Right Arrow" respectively.


  9. Copy and paste the following code into the Code window for Form1:
    
    
          Option Explicit
    
          Private Sub cmdLeftArrow_Click()
             Dim l
             Set l = ListViewCtrl1.ListItems.Add(, , "Left Arrow", 1)
          End Sub
    
          Private Sub cmdRightArrow_Click()
             Dim r
             Set r = ListViewCtrl1.ListItems.Add(, , "Right Arrow", 2)
          End Sub
    
          Private Sub Form_Load()
             'Add Images to ImageList
             ImageList1.Add ("\Windows\arrowl.2bp")
             ImageList1.Add ("\Windows\arrowr.2bp")
             'Make the images in ImageList control available for
             'the ListView control
             ListViewCtrl1.Icons = ImageList1.hImageList
         End Sub 


  10. Run the project in emulation. The necessary bitmap files are included in the emulator's \Windows folder.


NOTE: You can also add multiple images of the same height from one file containing one wider image. To see an example using the code above, replace the line:


Imagelist1.Add ("\windows\arrowl.2bp") 
with the lines:

ImageList1.ImageWidth = 109
   ImageList1.Add "\windows\wincelgo.bmp" 
When adding images, if the width of the image is not evenly divisible by the ImageWidth set above, it may appear distorted as the Imagelist control attempts to re-scale it.

Additional query words: vbce wince vbce5 vbce6

Keywords : kbToolkit kbVBp500 kbVBp600 kbWinCE100 kbGrpVB
Version : WINDOWS:
Platform : WINDOWS
Issue type : kbhowto


Last Reviewed: March 2, 1999
© 2000 Microsoft Corporation. All rights reserved. Terms of Use.