隐藏窗体不关闭 [英] Hidden form not closing
问题描述
我有一个C# Form
,其中您有 Form1
在开始处显示,当您按 Go
你被带到 Form2
。显示 Form1
并显示 Form2
。
现在当你退出 form2
时,应该关闭整个应用程序。当我按下退出按钮时,我正在使用 Application.Exit()
。
如果用户按 X 或 ALT + F4 或 RightClick->关闭
。
表单将关闭,但隐藏表单将保持打开状态。
我该如何解决这个问题?当我按下其中一个控制按钮时,所有隐藏的窗体也会关闭?
我试过 form1_Close
和 Form1_Closing
函数,但它们似乎并不奏效。 试试这个:
Hide();
Form2 form2 = new Form2();
form2.Closed + =(s,args)=> this.Close();
form2.Show();
关闭 Form1
code>窗体2 。如果用户按下 X 或 ALT + F4 或 RightClick - >关闭
Form 2
Form2
和隐藏的 Form1 code>将关闭。
I have a C# Form
, where you have Form1
shown at the start, and when you press Go
you are taken to Form2
. Form1
is hidden and Form2
is shown.
Now when you exit form2
, the whole application should be closed. I am using Application.Exit()
when I press the exit button.
I am facing problems if the user presses X or ALT+F4 or RightClick->Close
.
The form will close but the hidden form will stay opened.
How can I fix that? When I press one of these control button, for all hidden forms to also close?
I tried form1_Close
and Form1_Closing
function but they didn't seem to work.
Try this:
Hide();
Form2 form2 = new Form2();
form2.Closed += (s, args) => this.Close();
form2.Show();
This will close Form1
when you close Form2
. If the user presses X or ALT+F4 or RightClick -> Close
on Form2
The Form2
and the hidden Form1
will close.
这篇关于隐藏窗体不关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!