Home > DeveloperSection > Beginner > OpenFileDialog Control in C#.Net

OpenFileDialog Control in C#.Net


C# C# 
Ratings:
0 Comment(s)
 9325  View(s)
Rate this:

OpenFileDialog Control in C#.Net

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

 


Don't want to miss updates? Please click the below button!

Follow MindStick