If you would like to make some extra cash for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html
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 firstname.lastname@example.org
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 email@example.com
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.
This example assumes you have created a form and put the following controls on it:
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" thumb.DrawForm End Sub Private Sub Form_Resize() thumb.UpdateForm End Sub
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: http://www.codeoftheweek.com/membersonly/bi/0121.html
If you would like to get paid for surfing the web, jump to http://www.codeoftheweek.com/paidsurf.html