The Picturebox control is used in displaying graphics in different format like bitmap, PNG, JPEG metafile and icon format. And we can set the image property on both design time or at run time.
This time, create a new visual basic project and name it as “picturebox” and drag a picturebox on the form.
Here’s the following steps to display a graphic into a picture box:
• Select the picturebox
• Then, on the property window
• Choose the image property and click the ellipse button
• Then a Select resource dialog will show and it looks like as shown below
• And on the Resource context, select the Local resource
• Next, click Import
• Then browse for a specific from your computer
• And click OK button.
• Then on the property window choose SizeMode
• And set it into StretchImage
• Finally, it will look like as shown below.
This time lets add image during design time and display it at run time. And here’s the following steps.
• First double click the form
• And add the following code
'get the image and display to picture box based on the image location specified
PictureBox1.ImageLocation = "C:\Users\Public\Pictures\SamplePictures\koala.jpg"
'set the size Mode into StretchImage
PictureBox1.SizeMode = PictureBoxSizeMode.StretchImage
• Then press “F5”
• And the output will now look like as shown below.