Windows Forms: How to Upload/Display Image In Picture Box Using C#

This post shows you How to Upload/Display Image In Picture Box Using C# Windows Forms Application.

Dragging PictureBox, TextBox, Button control from your Visual Studio toolbox into your form designer. You can modify your layout as shown below.

How to show image in picturebox in c# using openfiledialog

Upload/Display Image In Picture Box Using C#

Adding a click event handler to the Upload button allows you to select an image file, then display the image in your PictureBox control.

How to display image in picturebox in c#

private void btnUpload_Click(object sender, EventArgs e)
{
    //c# open file dialog with image filters
    using (OpenFileDialog ofd = new OpenFileDialog() { Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp; *.png)|*.jpg; *.jpeg; *.gif; *.bmp; *.png" })
    {
        if (ofd.ShowDialog() == DialogResult.OK)
        {
            //c# display image in picture box  
            pictureBox1.Image = new Bitmap(ofd.FileName);
            //c# image file path  
            txtFileName.Text = ofd.FileName;
        }
    }
}

Using OpenFileDialog class with the Filter property allows the user to select only valid image files, then display image in picturebox in c# using path.