Return to previous form

1

Having a main form with a button with which I access the second form, how can I return to the main form by closing the second form with the x button?

Form1:

private void buttonEnterAdmin_Click(object sender, EventArgs e)
{
    this.Hide();
    Login login = new Login();
    login.Show();
}

Form2:

private void Login_FormClosed(object sender, FormClosedEventArgs e)
{
    Main main = new Main();
    main.Show();
}
    
asked by Neon 30.04.2018 в 22:21
source

1 answer

1

You can use the FormClosed event Subscribe to the event and you can open it the moment you close it

A small example

void SegundaForm_FormClosed(object sender, FormClosedEventArgs e)
{
 #Codigo
 Form2 primeraForm = new Form2();
 primeraForm.Show();
}

Source of documentation: Event FormClosed

If you need the event to fire before the form closes Use The Form.FormClosing event Event Form.FormClosing

Since the FormClosing event I understand is triggered before FormClosed

    
answered by 30.04.2018 / 22:31
source