Loading a Bitmap Image into a PictureBox from an OpenFileDialog.
Code: Select all
public void openBMP()
{
//Declare the OpenFileDialog as a new OpenFileDialog.
OpenFileDialog openFileDialog = new OpenFileDialog();
//Declare the PictureBox as a new PictureBox
PictureBox picBox = new PictureBox();
//Set the openFileDialog's Filter.
openFileDialog.Filter = "Bitmap Image|*.bmp|All Files|*.*";
//Set the openFileDialog's FileName to nothing.
openFileDialog.FileName = string.Empty;
//Show the openFileDialog
if (openFileDialog.ShowDialog(this) == DialogResult.OK)
{
//To do code if the Open button was pressed
//Use something like:
picBox.Image = Image.FromFile(openFileDialog.FileName);
}
else
{
return;
}
}