单击按钮并同时关闭第一个表单时如何打开另一个表单?

单击按钮并同时关闭第一个表单时如何打开另一个表单?

问题描述:

您好!我想要一个按钮,就像一个启动屏幕。因此,当您按下按钮时,它会显示一个新表格并关闭第一个表格。怎么样,我会这样做吗?

Hello! I am trying to have a button, like a startup screen. So, when you press the button it shows a new form and closes the first one. How, would i do that?

以下似乎可以满足您的需求。注意当子表单关闭时,隐藏的主表单将关闭并返回关闭应用程序。

The following appears to meet your needs. Note when the child form closes the main form which has hidden will close and in return close the application.

private void OnButton1Click(object sender, EventArgs e)
{
    this.Hide();
    var form2 = new Form2();
    form2.Closed += (s, args) => this.Close(); 
    form2.Show();
}