winform 窗体Form2里面,点击窗体右上角“X”关闭窗体,跳到上一个界面Form1

这里有两种方法:一个是重写OnClosing方法;另一个是点击窗体事件FormClosing;

一、重写OnClosing方法

        protected override void OnClosing(CancelEventArgs e)
        {
            e.Cancel = true;
            Form1 f = new Form1();
            f.Show();
            this.Hide();
        }

二、点击窗体事件FormClosing

       private void Form2_FormClosing(object sender, FormClosingEventArgs e)
        {
            Form1 f = new Form1();
            f.Show();
            this.Hide();
        }

相关文章:

  • 2022-02-25
  • 2022-12-23
  • 2022-12-23
  • 2021-11-11
  • 2022-02-01
  • 2022-12-23
猜你喜欢
  • 2021-10-04
  • 2022-12-23
  • 2021-09-15
  • 2022-12-23
  • 2021-07-18
  • 2021-10-19
相关资源
相似解决方案