articles

OpenFileDialog Control in C#.Net

Pushpendra Singh14141 24-Jan-2011

An OpenFileDialog control is used to select a file. OpenFileDialog provide files to the user and retrieves the user's file selection back to the program.

How to use OpenFileDialog Control

Drag and drop OpenFileDialog control from toolbox on the window Form.

OpenFileDialog Control in C#.Net

OpenFileDialog Control in C#.Net

Drag and drop PictureBox and Button.

OpenFileDialog Control in C#.Net

Code:

Write code in Button click event.

OpenFileDialog Control in C#.Net

Double click on Click event to open Button click event handler.

private void btnOpenFile_Click(object sender, EventArgs e)
{
       // OpenFileDialog will open
       openFileDialog1.ShowDialog();
       // selected Image will show in the pictureBox
       pictureBox1.Image = Image.FromFile(openFileDialog1.FileName);
}

Run the project

OpenFileDialog Control in C#.Net

When you click SelectImage button then OpenFileDialog will open.

OpenFileDialog Control in C#.Net

Select Image which you want to show in the PictureBox. When you select Image and click open then selected Image will show in PictureBox on the Form.

OpenFileDialog Control in C#.Net

 


Updated 07-Sep-2019

Leave Comment

Comments

Liked By