5.1 Loading an Image in a Picture Box
5.1.1 Loading an Image at Design Time
Let us create an image viewer. To design the UI, insert a picture box in the form. Next, change its border property to FixedSingle and its background color to white. Besides that, change the SizeMode property of the image to StretchImage so that the image can fit in the picture box.
Now, right click on the picture box to bring out its properties window. In the properties window, scroll to the Image property, as shown in Figure 5.1. In the properties window, click on the grey button on the right of the Image item to bring out the “Select Source” dialog box, as shown in Figure 5.2
Figure 5.1
Figure 5.2
The next step is to select a local resource and click on the Import button to view the available image files in your local drives, as shown in Figure 5.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 5.4
Figure 5.3
Figure 5.4
5.1.2 Loading an Image at Runtime
To load an image at runtime, use the code as in Example 5.1.
Example 5.1 Loading an Image at Runtime
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load MyPicBox.Image = Image.FromFile("C:\Users\Documents\My Websites\vbtutor\images\vb6_cover.jpg") End Sub |
* You must search for an image in your local drive and determine its path.
Running the program will display the same image in the picture box as in Figure 5.4
0 Comments
Thanks for your comment.
i will reply you soon.