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.
Drag and drop PictureBox and Button.
Code:
Write code in Button click event.
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
When you click SelectImage button then OpenFileDialog will open.
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.
Leave Comment