本文介绍了在Windows 7中无法打开OpenFileDialog的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在Windows XP上使用Visual Studio 2008,问题是我试图打开一个文件对话框以选择一个文件,在WinXP上这可以正常工作,但在Windows7上却没有显示文件对话框.这是我的代码
I am using Visual Studio 2008 on Windows XP, the problem is that I am trying to open a file dialog box to select a file, and on WinXP this works fine but on Windows7 the file dialog does not show. This is my code
OpenFileDialog FD = new OpenFileDialog();
FD.Title = "Images";
FD.Filter = "Png Images| *.png";
FD.ShowDialog();
if (FD.FileName.ToString() != "")
{
pngImage.ImageLocation = FD.SafeFileName.ToString();
img = new Bitmap(FD.SafeFileName.ToString());
}//end if
推荐答案
OpenFileDialog openFileDialog1 = new OpenFileDialog();
openFileDialog1.InitialDirectory = "c:\\";
openFileDialog1.Filter = "All files (*.*)|*.*";
openFileDialog1.FilterIndex = 1;
openFileDialog1.RestoreDirectory = true;
if (openFileDialog1.ShowDialog() == DialogResult.OK)
{
//openFileDialog1.FileName
}
这个在win7中对我有用
This one works for me in win7
FD.FileOk += new CancelEventHandler(openFileDialog1_FileOk);
private void openFileDialog1_FileOk(object sender,
System.ComponentModel.CancelEventArgs e)
{
if (FD.FileName.ToString() != "")
{
pngImage.ImageLocation = FD.SafeFileName.ToString();
img = new Bitmap(FD.SafeFileName.ToString());
}//end if
}
这篇关于在Windows 7中无法打开OpenFileDialog的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!