Skip to main content

Past Blast

Featured Products

Windows Mobile Developer Controls
Windows Mobile Developer Controls
Stay in touch using the DEVBUSS RSS feeds.
 

News

Windows Mobile Developer Controls
Windows Mobile Developer Controls

Adding images to the eVB Imagelist control

Written by Derek Mitchell  [author's bio]  [read 39885 times]
Edited by Derek

Page 1 

This week I would like to share how to add images to an Imagelist control and then show you how to reference the images in this control. The Imagelist control is quite different from its standard Visual Basic counterpart, so it is useful to know where to start.

First let me state, for those who are new to Imagelist controls, that the control offers a way to maintain a list of images for use by other controls. Controls that use the Imagelist control are the TreeView, ListView, CommandBar, MenuBar, and TabStrip controls. The images in the Imagelist control are referenced by their index value. So, if the first image is '\My Documents\icon_open_folder.bmp' then its index value is 1, and if the second file in the list is '\My Documents\icon_closed_folder.bmp' then its index value is 2, and so forth.

First add the Imagelist control to your form. The images will be added to the Imagelist at runtime using the syntax below, only images that are in .bmp, .dib, or .2bp formats can be used.

To add an image to the Imagelist control use the following syntax:

Imagelist.add(filename)

Keep in mind that the size of the first image is used for all the images in the Imagelist.

1) Add an Imagelist control to your form and add the two image files we mentioned above to the control using the following code:

Private sub form_load()
'Add images to the image list
Imagelist1.add("\My Documents\ icon_open_folder.bmp")
Imagelist1.add("\My Documents\ icon_closed_folder.bmp")
'set the TreeView control's imagelist property to the
'handle of the Imagelist control. This enables the
'TreeView control to reference Imagelist control
TreeView1.Imagelist = Imagelist1.hImagelist
End sub

2) Use the following syntax to assign an image to a control, in this example the TreeView control is used:

Private sub FillTreeView()
'Write code to retrieve information to
'put in the 'TreeView control
'Specify the image that goes with each node …
TreeView1.Nodes.Item(Index).Image = 1
End If

The following code:

TreeView1.Nodes.Item(Index).Image = 1

will set the nodes image to "icon_open_folder.bmp" since it is the first image in the list. To reference the second image in the imagelist use simply point to the second item in the imagelist i.e.

TreeView1.Nodes.Item(Index).Image = 2