How do I make my Main Form know when a secondary form has been closed, without using Parent and Child?

3

I have my main form (image below), and in it a Split Container . I open a secondary form (what is currently being displayed) in panel2 of SplitContainer , in which the user selects an account to make financial transactions.

As soon as he chooses the account, and clicking the continuar button of this form, if everything is OK, the form selection should be closed and instead show another form with the available options.

How can I tell my main form that the form was closed, so that it can load the next form ?

>

I think of using events and delegate , is it correct?

    
asked by anonymous 30.01.2014 / 20:26

1 answer

4

Yes, it would be correct to use events or delegates in this case. In the case of WinForms , I see no problem putting an handler event in the parent parent%:

private void button1_Click(object sender, EventArgs e)
{
    var newForm = new Form1();
    newForm.Closed += newForm_Closed; ;
    newForm.ShowDialog();
}

void newForm_Closed(object sender, EventArgs e)
{
    button1.Text = "Fechado";
}

You could also pass OnClosed on the child form constructor and save the instance. So when closing, just call delegate .

    
30.01.2014 / 21:05