Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Know When Child Form Closed

Tags:

c#

winforms

I've a Form1 with a button. When you click the button, this code block executes:

Form2 frm = new Form2();
frm.Name = "Form" + musteriNumarasi.ToString();
frm.Text = "Kullanıcı - " + musteriNumarasi.ToString();

Lets say I've clicked three times. There are four forms now: Main, Child1, Child2, Child3. When user closes one of the child forms, main form needs to know which one is closed. How can I do that?

like image 320
Diga Avatar asked May 29 '15 18:05

Diga


2 Answers

Form2 frm = new Form2();   

frm.FormClosed += new System.Windows.Forms.FormClosedEventHandler(this.frm_FormClosed);

. . .

private void frm_FormClosed(object sender, EventArgs e)
{
    //Runs after closing child :)
}
like image 102
Kasra Avatar answered Oct 20 '22 12:10

Kasra


Subscribe to the Closed Event

Form2 frm = new Form2();    
frm.FormClosed += new FormClosedEventHandler(Form_Closed);

void Form_Closed(object sender, FormClosedEventArgs e)
{
    Form2 frm = (Form2)sender;
    MessageBox.Show(frm.Name);
}
like image 38
Rick S Avatar answered Oct 20 '22 12:10

Rick S