7.1 Loading An Image in A Picture Box
7.1 Loading An Image in A Picture Box
Next, click on the grey button on its right to bring out the “Select Source” dialog , as
shown in Figure 7.2
Figure
7.2: Select Source Dialog
Now select local source and click on the Import button to bring up the Open dialog and
view the available image files in your local drives, as shown in Figure 7.3
Figure 7.3
Finally, select the image you like and then click the open button, the image will be
displayed in the picture box, as shown in Figure 7.4
Figure 7.4
PictureBox1.Image =
Image.FromFile(“C:\Users\Toshiba\Pictures\sporetrip2014\fish.j
pg”)
End Sub
* You need to search for an image on your local drive and determine its path before you
write the code. Running the program will display the same image in the picture box as in
Figure 7.4
as shown in Figure 7.5. These are the common image file formats. Besides that, you
also need to delete the default Filename.
Figure
7.5: Properties Window of OpenFileDialogNext, double-click on the View button and enter
the following code:
Private Sub BtnView_Click(sender As Object, e As EventArgs)
Handles Button1.Click
If OFGSelectImage.ShowDialog = DialogResult.OK Then
PictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)
End If
End Sub
Press F5 to run the program and click the View button, a dialog box showing all the
image files will appear, as shown in Figure 7.6
Figure 7.6
Please notice that that the default image file is JPEG as we have placed it in the first
place in the Filter property. Selecting and opening an image file will load it in the picture
box, as shown in Figure 7.7
Figure 7.7