单击按钮并同时关闭第一个表单时如何打开另一个表单? [英] How to open another form when clicking on a button and close the first form at the same time?

查看:66
本文介绍了单击按钮并同时关闭第一个表单时如何打开另一个表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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();
}


这篇关于单击按钮并同时关闭第一个表单时如何打开另一个表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆