Warning: file_get_contents(/data/phpspider/zhask/data//catemap/4/macos/8.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# 表单关闭类型为'的未处理异常;System.ComponentModel.Win32Exception';发生在System.Windows.Forms.dll中_C#_Forms - Fatal编程技术网

C# 表单关闭类型为'的未处理异常;System.ComponentModel.Win32Exception';发生在System.Windows.Forms.dll中

C# 表单关闭类型为'的未处理异常;System.ComponentModel.Win32Exception';发生在System.Windows.Forms.dll中,c#,forms,C#,Forms,您好,我有一个表单,我想在用户关闭当前表单时打开另一个表单,您可以在此处看到: private void frmDashboard_FormClosing(object sender, FormClosingEventArgs e) { this.Close(); frmConcerns a = new frmConcerns(); a.ShowDialog(); } 但是,当我单击“关闭”

您好,我有一个表单,我想在用户关闭当前表单时打开另一个表单,您可以在此处看到:

private void frmDashboard_FormClosing(object sender, FormClosingEventArgs e)
        {
            this.Close();
            frmConcerns a = new frmConcerns();
            a.ShowDialog();
        }
但是,当我单击“关闭”按钮时,会出现以下错误:

An unhandled exception of type 'System.ComponentModel.Win32Exception' occurred in System.Windows.Forms.dll

Additional information: Error creating window handle.
this.Close()
关闭当前表单-这实际上已经完成了,因为否则就不会调用
FormClosing
事件删除该行

此外,如果希望将对话框显示为模式窗口,则应提供父窗体,而不是调用
a.ShowDialog()而不是调用
a.ShowDialog(这个)


如果错误仍然存在,我可以向您保证,在我建议的修改之后,您显示的代码将是正确的——我以前也做过类似的事情。在这种情况下,错误必须发生在您未向我们展示的代码的其他部分。

这通常会导致StackOverflowException崩溃。您的Close()调用会再次触发FormClosing事件。我怀疑您的真实代码与此略有不同,您实际上创建了一万个对话框。在此之后,操作系统将拔掉插头,不允许您再创建任何窗口。不要调用Close(),它已完成。