Ad Code

PictureBox In C#

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.

PictureBox in C#



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.

After writing the code, compile the program and if any issue comes, you can comment us or you can watch a video on this topic on our YouTube Channel





Display Picture at Design time

If you want to set any picture at design time, like if you want to show your logo somewhere on the form, then you can set the picture at design time. 

STEP 1: You have to drag and drop the picture box where you want to show the image and click on the picture box and click on this icon and set the picture with the help of the choose image option. And at the same time you can change the image size mode according to your picture.


If any issue comes to you even after that, please comment us.


Post a Comment

0 Comments

Ad Code