简体   繁体   中英

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

如何通过使用OpenFileDialog设置PictureBox控件的Image属性?

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);
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM