当用户单击OpenFileDialog中的CANCEL按钮时,程序崩溃(我认为是因为程序正在继续)。当用户单击“取消”时,如何关闭对话框而不退出程序?
Stream myStream;
OpenFileDialog ofd = new OpenFileDialog();
if (ofd.ShowDialog() == DialogResult.OK)
{
if ((myStream = ofd.OpenFile()) != null)
{
string strfilename = ofd.FileName;
string filetext = File.ReadAllText(strfilename);
txtMain.Text = filetext;
textBox2.Text = Path.GetFileName(strfilename);
}
}
当用户单击“取消”时: 实际结果:错误 预期结果:对话框关闭,返回主窗体