The Picture Viewer Project

The third step is to display a picture when the user selects a picture in the combo box.
The user must first select a folder and all of the filenames are displayed in the combo box.
Make sure that that step is working, then add the code to display the picture when the selected index changes.

Continue with the PictureViewer application.

Double click on the cboPictures combo box and write the code shown below:

    Private Sub cboPictures_SelectedIndexChanged(sender As System.Object, e As System.EventArgs) Handles cboPictures.SelectedIndexChanged
Dim pathAndFileName As String = FolderBrowserDialog1.SelectedPath & "\" & cboPictures.Text 'we need both the folder and the filename to load the picture.
Me.Text = pathAndFileName
PictureBox1.Load(pathAndFileName)
End Sub

Test your program and try opening a folder. You should see all the picture files in the combo box and the first one displays.
If the picture shows only one corner, make sure you have set the sizemode to stretch for the picture box.

Save all before moving on to the next step, using a timer to create a slide show.


INDEX, Viewing a Picture, Code and instructions to view a picture, Select a folder, Display the picture selected in the combo box, Use a timer to create a slide show
Next lesson: The Pizza Project

Copyright © Zebra0.com
All rights reserved worldwide.

 
 

Display the picture selected in the combo box