这是关于openfiledialog [英] this is about openfiledialog
本文介绍了这是关于openfiledialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
打开文件(只是诸如.jpg,.png,bmp之类的图像)的代码是什么?
what is the code for open a file (Just images such as .jpg, .png, bmp)?
推荐答案
请参见 ^ ]属性.
See the OpenFileDialog.Filter[^] property.
myOpenFileDialog.Filter = "Bitmap Files (*.bmp)|*.bmp|All Files (*.*)|*.*";
如果您不确定可以打开哪些图像文件,则此处有代码可以为您找到: ^ ]
顺便说一句:我不知道谁对你投了反对票-这不是一个愚蠢的问题-所以我用5来弥补.
If you aren''t sure what image files you can open, there is code here which will find out for you: A FileDialog.Filter generator for all supported images[^]
BTW: I don''t know who down voted you - it''s not a silly question - so I have compensated with a five.
您可以使用如下代码:
You can use a code like this:
private void button1_Click(object sender, System.EventArgs e)
{
Stream myStream = null;
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\" ;
openFileDialog1.Filter = "txt files (*.jpg)|*.bmp|All files (*.*)|*.*" ;
openFileDialog1.FilterIndex = 2 ;
openFileDialog1.RestoreDirectory = true ;
if(openFileDialog1.ShowDialog() == DialogResult.OK)
{
try
{
if ((myStream = openFileDialog1.OpenFile()) != null)
{
using (myStream)
{
// Insert code to read the stream here.
}
}
}
catch (Exception ex)
{
MessageBox.Show("Error: Could not read file from disk. Original error: " + ex.Message);
}
}
}
希望对您有帮助...
Hope it''s helpful...
这篇关于这是关于openfiledialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文