点击一下关闭两个表单? [英] Close two form by one click?
问题描述
我正在使用登录功能进行项目工作
当我运行项目时,有一个窗体( form1
)运行登录。
之后,我点击登录按钮建立另一个表单( form2
) - 这是我的程序的形式。
并将第一个表单( form1
)隐藏起来。
问题是当我按下在form2中的X按钮它是关闭的,但form1仍然在运行。
我试图关闭 form1
,而不是隐藏...但这会在启动前关闭 form2
$ b $
this.Hide();
Form2 x = new Form2();
x.Show();
您可以订阅子表单 FormClosed
事件并用它在父窗体上调用 Close
。
x.FormClosed + = new FormClosedEventHandler(x_FormClosed);
void x_FormClosed(Object sender,FormClosedEventArgs e)
{
this.Close();
}
I'm working on project with sign in feature
When I run the project there is a form (form1
) run the sign in .
after i click on login button build another form (form2
) - It's the form of my program .
and made the first form (form1
) hide .
The problem is when I press at the X button in form2 it's close but the form1 it's still running .
I tried to close the form1
instead of hide ... but this will close form2
before launching
In form1
:
this.Hide();
Form2 x = new Form2();
x.Show();
You could subscribe to the child forms FormClosed
event and use that to call Close
on the parent form.
x.FormClosed += new FormClosedEventHandler(x_FormClosed);
void x_FormClosed(object sender, FormClosedEventArgs e)
{
this.Close();
}
这篇关于点击一下关闭两个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!