Also Read
PictureBox in C#
The bitmap, GIF, icon, or JPEG formats are all supported by the Windows Forms PictureBox control for displaying images. At design time or during runtime, you can set the Image property to the image you wish to display. When you use a single form to display many pieces of information, you can modify the image that appears in a picture box programmatically.
In today's article we will learn how we can use PictureBox control in our project. We will see how we can show the image in the PictureBox and its path in the textbox at runtime. And at the same time we will also see how we can set the picture in the PictureBox at the designed time. I am using visual studio 2017 here, you can use any version.
Set Picture at Runtime
STEP 1. First, create the windows form project in Visual Studio.STEP 2. After you create the project, you will have a window like this.
- Change the Name property of the pictureBox as 'pbx' in the property window by dragging the picturebox from the toolbox.
- Drag two buttons from the toolbox, then give each one a name and some text.
- Set the TEXT property for the Browse button to Browse and the Name to 'btnBrowse'.
- Set the TEXT property for the Show Image Path button to Show Image Path and the Name to 'btnPath'.
- Drag the text box from the toolbox and change the Name of the textbox as 'txtPath'.
- Move the OpenFileDialog toolbox item onto the form.
STEP 3. Now you have to double click on the browse button and write this code.
STEP 4. Now you have to double click on the 'Show Image Path' button and write this code.
.png)





.png)
0 Comments