Lesson 21 ยท VB6 Tutorial

Creating a Picture Viewer in VB6

Build a professional image viewer application with file browsing capabilities

Lesson reading progress

Lesson Overview

Lesson 21 of 40
Topic VB6 Tutorial
Focus Concepts ยท Examples ยท Practice
Goal Hands-on Learning
Upgrade Path VB.NET / Visual Studio 2026

Key Takeaway

By leveraging VB6's file system components and image controls, you can create a versatile picture viewer that supports multiple image formats and provides an intuitive browsing experience.

Welcome to Lesson 21 of our Visual Basic 6 Tutorial! Building on your multimedia skills from Lesson 20, you'll now learn how to create a professional picture viewer application. This viewer will allow users to browse their storage devices, select image files, and display them with navigation controls.

21.1 Essential Components

To create a picture viewer, we'll use several key components:

File Browsing Controls

DriveListBox, DirListBox, and FileListBox for navigating files

Image Format Support

Supports BMP, JPG, GIF, WMF, and other image formats

Display Controls

PictureBox for image display with zoom and navigation features

21.1.1 Required Controls

Our picture viewer interface includes these essential controls:

1ComboBox

For selecting image file types (BMP, JPG, etc.)

2DriveListBox

To select available drives on the system

3DirListBox

To navigate through directories and subdirectories

4FileListBox

To display available image files

5TextBox

To display the selected file path

6PictureBox

For displaying the selected image

Picture Viewer Interface
Figure 21.1: The Picture Viewer Interface

21.2 Building the Picture Viewer

Our picture viewer follows a logical workflow to provide a seamless user experience:

1Select File Type

User chooses the image formats they want to view

2Choose Drive

User selects the storage device containing image files

3Browse Directories

User navigates to the folder containing image files

4Select File

User chooses an image file from the list

5View Image

User clicks "Show" to display the selected image

Interactive Picture Viewer

Try out the picture viewer below - navigate through images using the previous and next buttons:

Image Preview
Butterfly.jpg 1.2 MB
1 of 5

21.2.1 Implementing the Code

The core functionality is implemented through event handlers for each control. Here's the complete code for our picture viewer:

PictureViewer.vb
Private Sub Form_Load() 
    ' Center the form on screen
    Left = (Screen.Width - Width) \ 2 
    Top = (Screen.Height - Height) \ 2 
    
    ' Initialize file type options
    Combo1.Text = "All graphic files"
    Combo1.AddItem "All graphic files"
    Combo1.AddItem "All files"
End Sub 

Private Sub Combo1_Change() 
    ' Set file pattern based on selection
    If Combo1.ListIndex = 0 Then
        File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")
    Else
        File1.Pattern = ("*.*")
    End If
End Sub 

Private Sub Dir1_Change() 
    ' Update file list when directory changes
    File1.Path = Dir1.Path
    File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")
End Sub 

Private Sub Drive1_Change() 
    ' Update directory when drive changes
    Dir1.Path = Drive1.Drive
End Sub 

Private Sub File1_Click() 
    ' Handle file selection
    If Combo1.ListIndex = 0 Then
        File1.Pattern = ("*.bmp;*.wmf;*.jpg;*.gif")
    Else
        File1.Pattern = ("*.*")
    End If

    If Right(File1.Path, 1) <> "\" Then
        filenam = File1.Path & "\" & File1.FileName
    Else
        filenam = File1.Path & File1.FileName
    End If
    Text1.Text = filenam
End Sub 

Private Sub show_Click() 
    ' Display the selected image
    If Right(File1.Path, 1) <> "\" Then
        filenam = File1.Path & "\" & File1.FileName
    Else
        filenam = File1.Path & File1.FileName
    End If
    ' Load the picture into the picture box
    Picture1.Picture = LoadPicture(filenam)
End Sub 

21.2.2 Key Functionality Explained

The picture viewer relies on several important event handlers:

File System Navigation

The DriveListBox, DirListBox, and FileListBox work together to allow users to browse for image files.

Drive1_Change โ†’ Dir1_Change โ†’ File1_Click

Image Display

The show button handles different image formats and loads the selected image.

Picture1.Picture = LoadPicture(filenam)

File Pattern Handling

The ComboBox allows users to filter by specific image formats or show all files.

File1.Pattern = "*.bmp;*.wmf;*.jpg;*.gif"

Lesson Summary

In this lesson, you've learned how to create a professional picture viewer application in VB6:

File System Controls

Using DriveListBox, DirListBox, and FileListBox for navigation

Image Display

Implementing image loading with the PictureBox control

File Filtering

Creating filters for different image formats

Path Handling

Correctly constructing file paths for different directory structures

Important Note

The PictureBox control supports BMP, ICO, WMF, EMF, GIF, and JPG formats. For other formats like PNG, you may need additional libraries or Windows API calls.

Practice Exercises

Test your picture viewer programming skills with these exercises:

Exercise 1: Image Navigation

Add previous and next buttons to navigate through images in a folder.

Exercise 2: Zoom Functionality

Implement zoom in/out controls to adjust the image size.

Exercise 3: Slideshow Mode

Add an automatic slideshow feature that cycles through images.

Exercise 4: Image Information

Display image metadata (dimensions, file size, format) when an image is selected.

Exercise 5: Thumbnail View

Create a thumbnail grid view of images in the current directory.

Next Lesson

Continue your VB6 journey with Lesson 22: Creating a Multimedia Player.

Related Resources

Full VB6 Tutorial Index

Complete list of all VB6 lessons with descriptions

Explore Tutorials

Visual Basic Examples

Practical VB6 code samples for real-world applications

View Examples

Audio Player Application

Learn to create an audio player in VB6

Previous Lesson

Multimedia Player

Learn to create a multimedia player application

Next Lesson