在Windows 7中无法打开OpenFileDialog [英] OpenFileDialog does not open in Windows 7

查看:102
本文介绍了在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

推荐答案

该代码在哪里调用?是在Form_Load或Form_Shown事件中的某个位置-在某些情况下,不会显示在那里引发的异常.
您可以逐步调试程序直到ShowDialog()调用吗?
Where is that code called? Is it somewhere in a Form_Load or Form_Shown event - under some circumstances, exceptions thrown there are not shown.
Can you debug the program step by step downto the ShowDialog() call?


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的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆