Reputation: 491
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?
Upvotes: 10
Views: 12051
Reputation: 41
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 :)
}
Upvotes: 3
Reputation: 6586
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);
}
Upvotes: 22
Reputation: 339
add these lines to your code to handle the event of closed Or Closing Form
frm.Closing += Form_Closing;
frm.Closed += Form_Closed;
add the following Methods to the current Class
void Form_Closing (object sender,EventArgs e){
//Handler form Closing Event
}
void Form_Closed (object sender,EventArgs e){
//Handler form Closed Event
}
Upvotes: -2