MaskColor Property Example

This example loads several bitmaps into an ImageList control. As you click the form, one ListImage object is overlaid on one of the other ListImage objects. To try the example, place an ImageList control and a Picture control on a form and paste the code into the form's Declarations section. Run the program and click the form.

Private Sub Form_Load()
   Dim imgX As ListImage
   
   ' Load bitmaps.
   Set imgX = ImageList1.ListImages. _
   Add(, "No", LoadPicture("bitmaps\assorted\Intl_No.bmp"))
   Set imgX = ImageList1.ListImages. _
   Add(, , LoadPicture("bitmaps\assorted\smokes.bmp"))
   Set imgX = ImageList1.ListImages. _
   Add(, , LoadPicture("bitmaps\assorted\beany.bmp"))

   ScaleMode = vbPixels
   ' Set MaskColor property.
   ImageList1.MaskColor = vbGreen
   ' Set the form's BackColor to white.
   Form1.BackColor = vbWhite
End Sub

Private Sub Form_Click()
   Static intCount As Integer ' Static variable to count images.
   
   ' Reset variable to 2 if it is over the ListImages.Count value.
   If intCount > ImageList1.ListImages.Count Or intCount < 1 Then
      intCount = 2 ' Reset to second image
   End If

   ' Overlay ListImage(1) over ListImages 2-3.
   Picture1.Picture = ImageList1.Overlay(intCount, 1)
   ' Increment count.
   intCount = intCount + 1
   
   ' Create variable to hold ImageList.ImageWidth value.
   Dim intW
   intW = ImageList1.ImageWidth
      
   ' Draw images onto the form for reference. Use the ImageWidth
   ' value to space the images.
   ImageList1.ListImages(1).Draw Form1.hDC, 0, 0, imlNormal
   ImageList1.ListImages(2).Draw Form1.hDC, 0, intW, imlNormal
   ImageList1.ListImages(3).Draw Form1.hDC, 0, intW * 2, imlNormal
End Sub