ARTICLE

Upload/Display Image in Picture Box Using C#

Posted by Muhammad Irfan Articles | Windows Forms C# June 17, 2010
In this article, we learn how to browse, view and display an image path in a picture box tool using C# Windows Forms application.
Reader Level:
Download Files:
 


Introduction:

Browsing and displaying an image in picture box tool using  Windows Forms application is a very simple task. In this application, we use the following classes/controls to do the b.

- OpenFileDialog
- PictureBox
- TextBox
- Button


Main Functions:

This functions simply perform the following steps:
1. Open a file dialog box so that a user can select an image from his/her machine
2. Browse the image
3. Display selected image in a picture box on a Form 
4. Display image file path in text box

Here is the code:
// open file dialog
 OpenFileDialog open = new OpenFileDialog();
 // image filters
 open.Filter = "Image Files(*.jpg; *.jpeg; *.gif; *.bmp)|*.jpg; *.jpeg; *.gif; *.bmp";
 if (open.ShowDialog() == DialogResult.OK)
{
   // display image in picture box
   pictureBox1.Image = new Bitmap(open.FileName);
    // image file path
    textBox1.Text = open.FileName;
  }

What is an image filter?

Image filter is basically a filter that restrict user to select only valid image file. You can remove image filter. 

Login to add your contents and source code to this article
post comment
     

Awesome!!! :) but I don't know how to save it into my database :( Could you guide for me?

Posted by Uyen Pham Apr 06, 2013

Awesome!!! :) but I don't save it into my database :(

Posted by Uyen Pham Apr 06, 2013

Garg, upload your code here and I'll check it.

Posted by Muhammad Irfan Feb 18, 2013

i have write same code but it save all type of files

Posted by gourav garg Feb 18, 2013

i have write same code but it save all type of files

Posted by gourav garg Feb 18, 2013
COMMENT USING
PREMIUM SPONSORS
DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and add new content to existing PDF documents from within your applications.
Get Career Advice from Experts
SPONSORED BY
  • PDF reports have never been easier to create. With our included WYSIWYG Designer, you can layout your reports, set up your data source and let DynamicPDF ReportWriter do the rest.
Join a Chapter