Visual Basic Code of the Week (COTW)
Issue #121
Online Version at (paid subscribers only)
All content and source code is Copyright (c) 2000 by C&D Programming Corp. No part of this issue can be reprinted or distributed in any manner without express written permission of C&D Programming Corp.

Issue topic: Thumbnail Image Viewer class

Earn REAL money surfing the web!

If you would like to make some extra cash for surfing the web, jump to


In this Issue

In this issue we discuss how to create an thumbnail image viewer. The basic idea here is to create a scrollable window that can display many images at once. Most image management programs contain this feature.

If you have any questions about using this module, let us know at


This class takes a form with a couple of controls on it (two picture boxes and a vertical scroller control) and turns it into a easy-to-use image viewer. It supports three different image sizes.

We are planning on expanding this module to include routines to aid in the creation of a full-blown image viewer. With the proliferation of digital cameras and online images we have been receiving many requests for routines to help manage these graphics. If you have any suggestions, drop us an email at

NOTE: You can use last weeks' issue to create thumbnail versions of all the graphics within a directory and then point this viewer class to the directory you created the thumbnails in. This can speed up the performance of this thumbnail viewer tremendously. Another useful feature would be the autogeneration of the thumbnail images on the fly to speed up future viewing of the images.


Public ParentForm As Form

The form that will be the image viewer form. This form must have a picture box (with an Index value of zero) control within a container control (another picture box works fine) and a vertical scroller (VScrollBar) control.

Public PictureFolder As String

Folder name which contains the graphics to display. This should be the fully qualfied path name, such as c:\windows or e:\pics\thumbs

Public ThumbnailSize As eThumbSize

This determines the size of the thumbnail graphic. It can be one of the following: ethSmall, ethMedium, ethLarge.

Public WithEvents Scroller As VScrollBar

This property needs to be set to the vertical scroller that is on the image form. The class will automatically manage this scroller and respond to the change event to scroll the window around.

Public Property Set ImageControl(img As Object)

The picture box control to use as the individual image viewer. The control assigned to this property must be a PictureBox with an Index value of zero. This class will NOT work unless this control has an index of zero. In Visual Basic 6.0 a feature which allows you to create controls on the fly would eliminate this necessity.


Public Sub DrawForm()

Initializes the form. This should be called after assigning the above properties. It will scan the folder specified in PictureFolder and load all the filenames into a collection for later use by the UpdateForm method.

Public Sub UpdateForm(Optional bLoadImageControls As Boolean = False)

This method should be called in the Form_Resize event of the form assigned to ParentForm. It recalculates the window size, determines how many images can fit across and down the window and adjusts the vertical scroller appropriately. If the bLoadImageControls parameter is set to True then all the images will be reloaded from disk (or wherever they were loaded from). When it is set to false it will use the last displayed images and just rearrange the images to fit within the window parameters.

Sample Usage

This example assumes you have created a form and put the following controls on it:

  • A picture control that will act as a container control called whatever you like.
  • Another picture control called pic that will be added within the container control added above. To do this, just select the container control and then add the picture control within it.
  • A vertical scroller control called vsScroll.
            Dim thumb As New cThumbnailViewer
            Private Sub Form_Load()
                Set thumb.Scroller = vsScroll
                Set thumb.ParentForm = Me
                Set thumb.ImageControl = pic
                thumb.ThumbnailSize = ethSmall
                thumb.PictureFolder = "c:\windows"
            End Sub
            Private Sub Form_Resize()
            End Sub

    Source Code

    To see the source code for this issue you must be a subscriber to Code of the Week. If you are a subscriber the source code is available at the following address:

    This document is available on the web

    Paid subscribers can view this issue in HTML format. There is no additional source or information in the HTML formatted document. It just looks a little better since we have included some HTML formatting. Just point your browser to link at the top of this document.

    Get paid to surf the web!

    If you would like to get paid for surfing the web, jump to

    Other links

    Contact Information

    C&D Programming Corp.
    PO Box 20128
    Floral Park, NY 11002-0128
    Phone or Fax: (212) 504-7945