English | 简体中文 | 繁體中文 | Русский язык | Français | Español | Português | Deutsch | 日本語 | 한국어 | Italiano | بالعربية

Simple Example of Closing Parent Window When Child Window Closes in C#

Body1It is actually a communication problem between windows, in the form2 , open the form on2 Close the form when closing1

Implementation method:

In the child window form2Declare the event in the

public delegate void childclose();
  public event childclose closefather;
  Then trigger this event in its closing event:
   private void Form2_Closed(object sender, System.EventArgs e)
   {
    //Close the main window with an event
    closefather();
   }

In the parent window form1in (such as in the login window):

Then pop up the child form2Here is the way to write it in the place of the window form:

  Form2 ff=new Form2();
  ff.closefather+=new childclose(this.closethis); //closethis() is a method in the parent window
  ff.Show();
   public void closethis()
   {
     this.Close();
   }

This is the complete content of the simple example of closing the parent window when the child window is closed that the editor shares with everyone. I hope it can be a reference for everyone and I hope everyone will support the Shouting Tutorial.

You May Also Like