欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

C#窗体跳转和隐藏原来的窗体

程序员文章站 2022-06-10 11:10:25
...

C#窗体如何从Form1跳转到Form2,同时隐藏Form1,关闭Form2时显示Form1

Form1,Form2的代码如下

    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void button1_Click(object sender, EventArgs e)
        {
            this.Visible = false;
            Form2 f = new Form2(this);
            f.Visible = true;
        }
    }
    public partial class Form2 : Form
    {
        public static Form2 frm2;
        private Form1 returnForm1 = null;
        public Form2(Form1 F1)
        {
            InitializeComponent();
            this.returnForm1 = F1;
            frm2 = this;
        }
        private void button2_Click(object sender, EventArgs e)
        {
            this.Close();
            this.returnForm1.Visible = true;
        }
    }
相关标签: 笔记 c#