简体   繁体   English

如何检测表单何时从另一个仍然打开的表单关闭?

[英]How to detect when a form is closing from another form still open?

我只是想知道如何检测表单何时从另一个表单关闭,假设我让我的主客户端打开另一个名为发件人的表单,我将如何检测发件人表单何时从主客户端表单关闭?

Attach an event handler to the form's closing event.将事件处理程序附加到窗体的关闭事件。

This will allow you to do whatever it is you want to do when the form closes.这将允许您在表单关闭时做您想做的任何事情。

You can attach, from the "ANOTHER FORM", an event handler to the FormClosing event您可以从“ANOTHER FORM”将事件处理程序附加到FormClosing事件

form.FormClosing += (sender, eventArgs) =>
{
    //Do your magic here
};

There is also a System.Windows.Forms.Forms.Closing event but it has been deprecated since .NET 2.0还有一个System.Windows.Forms.Forms.Closing事件,但它自 .NET 2.0 起已被弃用

It can be done easier than with an event:它可以比事件更容易完成:

if (!otherForm.IsDisposed)
{
    // otherForm is still open
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM