Picture box is a control in Visual Basic 2017 that is used to display images.In lesson 3, we have already learned how to insert a picture box on the form in Visual Basic 2017. However, we have not learned how to load a picture in the picture box yet. In this lesson, we shall learn how to load an image into the picture box at design time and at runtime. Besides that, we shall also learn how to use a common dialog control to browse for image files in your local drives and then select and load a particular image in the picture box. 7.1 Loading an Image in a Picture Box 7.1.1 Loading an Image at Design TimeFirst, insert a picture box on the form and change its text property to Picture Viewer, its border property to FixedSingle and its background color to white.
![](/uploads/1/2/6/5/126575436/620692464.jpg)
You might also want to change the size mode 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 7.1. First, we add a button and change its text to View and its name to BtnView. Next, we add the OpenFileDialog control on the form. This control will be invisible during runtime but it facilitates the process of launching a dialog box and let the user browse his or her local drives and then select and open a file. In order for the OpenFileDialog to display all types of image files, we need to specify the types of image files under the Filter property.
![Add Add](/uploads/1/2/6/5/126575436/647953936.png)
Developer Community for Visual Studio Product family. This site uses cookies for analytics, personalized content and ads. Visual Studio for Mac.NET. Disable context menu for Open in Visual Studio. Windows 10.0 visual studio 2017 ide. S911415 reported Mar 09, 2017 at 03:40 PM. Show comments 13.
Before that, rename OpenFileDialog1 as OFGSelectImage. Next, right-click on the OpenFileDialog control to access its properties window.
![Picture box c# Picture box c#](/uploads/1/2/6/5/126575436/874460268.png)
Beside the Filter property, specify the image files using the format: JPEG Files.JPG GIF Files.GIF WIndows Bitmaps.BMPas 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 BtnViewClick(sender As Object, e As EventArgs) Handles Button1.ClickIf OFGSelectImage.ShowDialog = DialogResult.OK ThenPictureBox1.Image = Image.FromFile(OFGSelectImage.FileName)End IfEnd SubPress 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.6Figure 7.6Please 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.
![](/uploads/1/2/6/5/126575436/620692464.jpg)