yonan2236
yonan2236

Reputation: 13649

How to set the Image property of a PictureBox Control by using OpenFileDialog? C# winforms

How to set the Image property of a PictureBox Control by using OpenFileDialog?

Upvotes: 0

Views: 1418

Answers (1)

Filip Ekberg
Filip Ekberg

Reputation: 36327

Set PictureBox.Image using Image.FromFile

OpenFileDialog _openFileDialog = new OpenFileDialog();
_openFileDialog.FileOk += OpenFileDialogFileOk;
_openFileDialog.CheckFileExists = true;
_openFileDialog.CheckPathExists = true;
_openFileDialog.ShowDialog();

void OpenFileDialogFileOk(object sender, CancelEventArgs e)
{
    var imageInformation = new FileInfo(_openFileDialog.FileName);
    var sizeInBytes = imageInformation.Length;

    myPictureBox.Image = Image.FromFile(_openFileDialog.FileName);
}

Upvotes: 4

Related Questions