且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

关闭MDI子项将关闭父窗体

更新时间:2023-12-06 09:04:52

我认为您的应用程序正在关闭时出现以下类型的错误:



System.Windows.Forms.dll中发生'System.InvalidOperationException'类型的未处理异常



因为您正在尝试关闭正在创建的表单(应用程序创建句柄的加载事件中的子窗体。



您还应该看到这些信息:



附加信息:在执行CreateHandle()时无法调用Value Close()。



如果您没有看到此类错误消息,那么你还有别的错误。



正如Dave K.在他的解决方案中建议的那样,这里的答案永远不会执行创建子表单的代码unl ess条件满足。
I think your app is shutting down with an error of type:

"An unhandled exception of type 'System.InvalidOperationException' occurred in System.Windows.Forms.dll"

Because you are trying to Close the Form being created (child Form) in the Load Event where the Application is creating a Handle.

You should be seeing this information also:

"Additional information: Value Close() cannot be called while doing CreateHandle()."

If you are not seeing this type of error message, then you something else is wrong.

As Dave K. suggests in his solution, the answer here is never execute the code that creates the child Form unless the condition is satisfied.


Form_Load事件不是这样做的地方。在尝试创建子表单的实例之前,您应该检查此情况。
The Form_Load event is NOT the place to do this. You should be checking for this condition before you even try to create an instance of the child form.