A Picture Viewer Application

The second step is to add a timer and create a slide show..
When the user selects a folder all of the picture files in the folder are displayed in the combo box.
When the user selects one of the pictures from the combo box, that picture is now displayed in the picture box.

Continue with the PictureViewer application.

Add the following control to the project:

  • A timer: timer, timer1

Double click onTimer1 and write the code shown below:

Private Sub Timer1_Tick(sender As Object, e As EventArgs) Handles Timer1.Tick
        If cboPictures.Visible Then
            If cboPictures.SelectedIndex < cboPictures.Items.Count - 1 Then
                cboPictures.SelectedIndex += 1 'show next picture
            Else
                cboPictures.SelectedIndex = 0 'go back to first picture
            End If
        End If
End Sub

Next, we need to modify the code for opening a folder: In

Change this code

If cboPictures.Items.Count > 0 Then
   cboPictures.SelectedIndex = 0
   cboPictures.Visible = True
Else
   cboPictures.Visible = False
End If

To this code:

If cboPictures.Items.Count > 0 Then
   cboPictures.SelectedIndex = 0
   cboPictures.Visible = True
   Timer1.Interval = 6000
   Timer1.Enabled = True
Else
   cboPictures.Visible = False
   Timer1.Enabled = False
End If

Test your program and try opening a folder. You should see the names of the files, but the pictures don't display. This project is now finished!

Save all before trying some of the enhancements below..

Complete code

To do: There are many little enhancements that you could add to this project:

  • Let the user start and stop the slide show: add a menu item, click on the picture to stop the show.
  • Let the user change the size of the picture box: Click + and - to make the size of the picture box change.
  • Add an "about box" to the project.

NEXT: The Pizza Project