在C#应用程序中使用OpenFileDialog控件 [英] Using the OpenFileDialog control in a C# application
本文介绍了在C#应用程序中使用OpenFileDialog控件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我确定我曾经问过这个问题,但是搜索什么也没做,我完全忘记了怎么做.
I'm sure I've asked this question before but searching does nothing and I completely forgot how to do this.
我需要一种方法,让用户从硬盘驱动器中选择图片,然后使用该位置将该图片加载到Image类中.
I need a way to have a user choose a picture from their hard drive and load that picture to an Image class using the location.
我过去曾经这样做过,但是正如我所说,我不记得自己是怎么做到的.
I've done this in the past, but as I said I can't remember how I did it.
我知道您可以将文件类型过滤器应用于OpenFileDialog.
I know you can apply a file type filter to the OpenFileDialog.
private void LoadImageToMemory()
{
openFileDialog1.Filter = "JPEG | jpeg";
openFileDialog1.ShowDialog();
}
有指导吗?谢谢!
推荐答案
我知道了!
如果有人有相同的问题,这就是您的处理方法.
In case anyone has the same question, this is how you do it.
private void LoadImageToMemory()
{
openFileDialog1.Filter = "png files (*.png)|*.png|jpg files (*.jpg)|*.jpg";
openFileDialog1.Multiselect = false;
openFileDialog1.InitialDirectory = @"C:\";
openFileDialog1.Title = "Select a picture to transform.";
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
txtFileName.Text = openFileDialog1.FileName;
}
}
这篇关于在C#应用程序中使用OpenFileDialog控件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文