ImageHeight, ImageWidth Properties Example

This example loads an icon into an ImageList control, and uses the image in a ListView control. When the user clicks the form, the code uses the ImageHeight property to adjust the height of the ListView control to accommodate the ListImage object. To try the example, place ImageList and ListView 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()
   ' Create variables for ImageList and ListView objects.
   Dim imgX As ListImage
   Dim itmX As ListItem

   Form1.ScaleMode = vbPixels ' Make sure ScaleMode is set to pixels.
   
   ListView1.BorderStyle = FixedSingle ' Show border.
   ' Shorten ListView control so later contrast is more obvious.
   ListView1.Height = 50

   ' Put a large bitmap into the ImageList.
   Set imgX = ImageList1.ListImages. _
   Add(,, LoadPicture("bitmaps\gauge\vert.bmp"))
   
   ListView1.Icons = ImageList1 ' Set Icons property.
   
   ' Add an item to the ListView control.
   Set itmX = ListView1.ListItems.Add()
   itmX.Icon = 1   ' Set Icon property to ListImage 1 of ImageList.
   itmX.Text = "Thermometer"   ' Set text of ListView ListItem object.
End Sub

Private Sub Form_Click()
   Dim strHW As String
   
   strHW = "Height: " & ImageList1.ImageHeight & _
   "   Width: " & ImageList1.ImageWidth
   caption = strHW   ' Show dimensions.
   ' Enlarge ListView to accommodate the tallest image.
   ListView1.Height = ImageList1.ImageHeight + 50
End Sub