tags:

views:

23

answers:

1

I want to run some code in this context after the form created here closes.

Form1 Form1 = new Form1();
Form1.Show(); //<-After this closes, I want to run code from this context, using ShowDialog() is not an option
+1  A: 

just register for the FormClosing event of the Form

void MyClosingEvent(object o, FormClosingEventArgs args)
{
}

private void aboutToolStripMenuItem_Click(object sender, EventArgs e)
{
    Form1 form1 = new Form1();
    form1.FormClosing += new FormClosingEventHandler(MyClosingEvent);
    //Or if you have C# 2 or higher: 
    //form1.FormClosing += MyClosingEvent;
Brian R. Bondy
But the code needs to be executed from the context in which the form was created. There's a method in that context that I don't know how to trigger in the form without passing the first form as a parameter when the second form is being created...
Soo
@Soo then make that method public or make another method that calls that method public.
Brian R. Bondy
@Soo or else register for the event inside of the Form1 if you prefer.
Brian R. Bondy
@Brian, sorry I misunderstood your answer before you posted that code example. Thanks, I implemented your suggestion :)
Soo