Know when the baby's uniform closes

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

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

Suppose I clicked three times. Now there are four forms: Main, Child1, Child2, Child3. When the user closes one of the child forms, the main form must know which one is closed. How can i do this?

+6
source share
3 answers

Sign up for a 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); } 
+10
source

add these lines to your code to handle a closed or closing form event

 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 } 
-2
source
 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 :) } 
-2
source

Source: https://habr.com/ru/post/988193/


All Articles