c# 打开一个新表单然后关闭当前表单? [英] c# open a new form then close the current form?

查看:31
本文介绍了c# 打开一个新表单然后关闭当前表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

例如,假设我在表格 1 中,那么我想要:

For example, Assume that I'm in form 1 then I want:

  1. 打开表单 2(从表单 1 中的按钮)
  2. 关闭表单 1
  3. 关注表格 2

推荐答案

Steve 的解决方案不起作用.调用 this.Close() 时,当前表单与 form2 一起处理.因此你需要隐藏它并设置 form2.Closed 事件来调用 this.Close().

Steve's solution does not work. When calling this.Close(), current form is disposed together with form2. Therefore you need to hide it and set form2.Closed event to call this.Close().

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

这篇关于c# 打开一个新表单然后关闭当前表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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