Share via


Visual Basic: Windows Controls

Overlay Method Example

This example loads five ListImage objects into an ImageList control and displays any two images in two PictureBox controls. For each PictureBox, select an image to display from one of the two ComboBox controls. When you click the form, the code uses the Overlay method to create a third image that is displayed in a third PictureBox control. To try the example, place an ImageList control, two ComboBox controls, and three PictureBox controls on a form and paste the code into the form's Declarations section. Run the example and click the form.

  Private Sub Form_Load()
   Dim X As ListImage
   ' Add 5 images to a ListImages collection.
   Set X = ImageList1.ListImages. _
    Add(, , LoadPicture("icons\elements\moon05.ico"))
   Set X = ImageList1.ListImages. _
    Add(, , LoadPicture("icons\elements\snow.ico"))
   Set X = ImageList1.ListImages. _
    Add(, , LoadPicture("icons\writing\erase02.ico"))
   Set X = ImageList1.ListImages. _
    Add(, , LoadPicture("icons\writing\note06.ico"))
   Set X = ImageList1.ListImages. _
    Add(, , LoadPicture("icons\flags\flgfran.ico"))

   With combo1   ' Populate the first ComboBox.
      .AddItem "Moon"
      .AddItem "Snowflake"
      .AddItem "Pencil"
      .AddItem "Note"
      .AddItem "Flag"
      .ListIndex = 0
   End With
   
   With combo2   ' Populate the second ComboBox.
      .AddItem "Moon"
      .AddItem "Snowflake"
      .AddItem "Pencil"
      .AddItem "Note"
      .AddItem "Flag"
      .ListIndex = 2
   End With
   
   Picture1.BackColor = vbWhite   ' Make BackColor white.
   Picture2.BackColor = vbWhite
   Picture3.BackColor = vbWhite
End Sub

Private Sub Form_Click()
   ' Overlay the two images, and display in PictureBox3.
   Set Picture3.Picture = ImageList1. _
    Overlay(combo1.ListIndex + 1, combo2.ListIndex + 1)
End Sub

Private Sub combo1_Click()
   ' Change PictureBox to reflect ComboBox selection.
   Set Picture1.Picture = ImageList1. _
    ListImages(combo1.ListIndex + 1).ExtractIcon
End Sub

Private Sub combo2_Click()
   ' Change PictureBox to reflect ComboBox selection.
   Set Picture2.Picture = ImageList1. _
    ListImages(combo2.ListIndex + 1).ExtractIcon
End Sub