Monday, October 1, 2012

Closing Multiple Forms in C# ( including parent form )


Open Form2 from Form1, close Form1 from Form2


Form1:
    private void button1_Click(object sender, EventArgs e)
    {
        Form2 frm = new Form2(this);
        frm.Show();
    }
Form2:
public partial class Form2 : Form
{
    Form opener;

    public Form2(Form parentForm)
    {
        InitializeComponent();
        opener = parentForm;
    }

    private void button1_Click(object sender, EventArgs e)
    {
        opener.Close();
        this.Close();
    }
}

No comments:

Post a Comment