从form1打开form2并隐藏表单1,然后在关闭表单2时关闭表单1

时间:2014-09-06 17:27:59

标签: c# forms

好的,我有2个表格Form1和Form2。 问题:因此,当我单击Form1中的按钮并隐藏Form1时,我想打开Form2,之后我想在关闭Form 2时关闭Form1。

    private void button1_Click(object sender, EventArgs e)
    {
        Form1 f1 = new Form1();
        Form2 f2 = new Form2(textBox1.Text);
        f2.Show();
        this.Hide();

    }
}

    public Form2(string s)
    {
        InitializeComponent();
        label1.Text = s;
    }

2 个答案:

答案 0 :(得分:0)

试试这个。希望它会有所帮助:)

private void button1_Click(object sender, EventArgs e)
    {
        Form1 f1 = new Form1();
        Form2 f2 = new Form2(textBox1.Text);
        this.Hide();
        f2.ShowDialog();
        this.Close();

    }
}

    public Form2(string s)
    {
        InitializeComponent();
        label1.Text = s;
    }

答案 1 :(得分:0)

Form2 frm = new Form2();
frm.FormClosed += new FormClosedEventHandler(delegate(object s, FormClosedEventArgs e1) { this.Close(); });
this.Hide();
frm.Show();