Using a drop-down image box with images from an imagelist.

hi,

I'm building a status report.

For the performance indicators, I would like to display them as a colored circle. I have three images inside a imagelist content control, but I'm searching for a way to be able to change conveniently between the three images. Here's what it look like :

I already tried 3 options.

  1. A drop-down box with images inside to select the right color
  2. Clicking directly on the image to switch to another color
  3. Creating a userform to select a color.

The First one would be my favorite way of doing things, but when I used the "Microsoft ImageComboBox Control", I wasn't able to fill it with the image in my imageList. Just no image, nor text was being displayed, like so :

I used this piece of VBA code to fill the combobox which I inserted in a button_click function :

Set IndchPr.ImageList = ImageList21

ImageList21 is the name of the image list which have the 3 images (index 1 for green, 2 for yellow and 3 for red). IndchPr is the image combobox.

For the second solution, I think it couldn't easily be done because what tells it which image there is? If it can be done though, It would be my second prefered solution.

For the Userform solution, I couldn't call the image controlers on my document, I didn't know how.

Thanks in advance!

Jonathan

July 17th, 2012 12:40am

1. For your first option (A drop-down box with images inside to select the right color), here used controls are ImageCombo1 and ImageList1.

Code in ThisDocument:

' ############################################
' Add all images from ImageList to ImageCombo.
' ############################################
Sub AddImageComboByImageList()
    With ImageCombo1
        If Not .ImageList Is Nothing Then Set .ImageList = Nothing
       
        Dim intCountImages As Integer
       
        intCountImages = ImageList1.ListImages.Count
       
        If intCountImages > 0 Then
            Set .ImageList = ImageList1
           
            ' Clear the old items before adding new items.
            .ComboItems.Clear
           
            Dim i As Integer
           
            For i = 1 To intCountImages
                .ComboItems.Add , , , i
            Next
        Else
            MsgBox "There is no picture in the ImageList control."
        End If
    End With
End Sub

 

2. For your second option (Clicking directly on the image to switch to another color), here used the Image1 control.

Code in ThisDocument:

' Which index of the image displayed in the Image control (the index is which from the ImageList control).
Public g_ImageIndex As Integer

' ####################
' Document.Close event
' ####################
Private Sub Document_Close()
    If g_ImageIndex = 0 Then g_ImageIndex = 1
   
    On Error Resume Next
   
    ' Set a value for an entry in the Windows registry under the following subkey.
    ' HKEY_CURRENT_USER\Software\Microsoft\Office\version\Word\Data
    System.ProfileString("Data", "ImageIndex") = g_ImageIndex
End Sub

' ###################
' Document.Open event
' ###################
Private Sub Document_Open()
    On Error GoTo errResetValue
   
    ' Get a value for an entry in the Windows registry under the following subkey.
    ' HKEY_CURRENT_USER\Software\Microsoft\Office\version\Word\Data
    g_ImageIndex = System.ProfileString("Data", "ImageIndex")
   
errResetValue:
    g_ImageIndex = 1
End Sub

' #################
' Image.Click event
' #################
Private Sub Image1_Click()
    g_ImageIndex = g_ImageIndex + 1
   
    If g_ImageIndex > ImageList1.ListImages.Count Then g_ImageIndex = 1
   
    If ImageList1.ListImages.Count > 0 Then
        If Not Image1.AutoSize Then Image1.AutoSize = True
        Image1.Picture = ImageList1.ListImages(g_ImageIndex).Picture
    Else
        MsgBox "There is no picture in the ImageList control."
    End If
End Sub

 

3. For your third option (Creating a userform to select a color), which is not recommended, because you will switch to UserForm and Document frequently every time you select an image.

Free Windows Admin Tool Kit Click here and download it now
July 18th, 2012 9:28am

Hi Jonathan,

Have you read my reply? Does it work for you?

July 24th, 2012 8:21am

So I did this but how or where do I save the images I want to be a dropdown. (I am doing the same thing but would like a specific signature to show depending on which I select.

Free Windows Admin Tool Kit Click here and download it now
November 1st, 2014 10:08pm

This topic is archived. No further replies will be accepted.

Other recent topics Other recent topics