简体   繁体   English

C#中的FormClosing事件

[英]FormClosing event in C#

I'm doing a C# app with multiple Forms, like Help, Feedback, Register, Login, etc. I try to override the FormClosing, like when the user presses X in the upper right to close the form, to return to the previous form that was opened.我正在做一个带有多个 Forms 的 C# 应用程序,例如帮助、反馈、注册、登录等。我尝试覆盖 FormClosing,例如当用户按下右上角的 X 关闭表单时,返回到上一个表单那被打开了。

I tried something like this我试过这样的事情

private void QuestionForm_FormClosing(object sender, FormClosingEventArgs e)
{
            this.Hide();
            HelpForm help = new HelpForm();
            help.FormClosed += (s, args) => this.Close();
            help.Show();
}

but when I press X, only the Question Form closes, and the Help Form that let's say was the previous one, shows up like 0.1s and the whole app closes.但是当我按 X 键时,只有问题表关闭,而可以说是前一个的帮助表显示为 0.1 秒,整个应用程序关闭。

Acoording to the comments, We can find the solution to this problem is to use ShowDialog .根据评论,我们可以找到解决此问题的方法是使用ShowDialog

You can use this method to display a modal dialog box in your application.您可以使用此方法在您的应用程序中显示模式对话框。

When this method is called, the code following it is not executed until after the dialog box is closed.调用此方法时,直到对话框关闭后才会执行后面的代码。

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

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