Home > Backend Development > C#.Net Tutorial > C# case of closing child window and closing parent window

C# case of closing child window and closing parent window

黄舟
Release: 2017-03-21 11:46:30
Original
2362 people have browsed it

The following editor will bring you a simple example in C# of closing the child window and closing the parent window. The editor thinks it is quite good, so I will share it with you now and give it as a reference for everyone. Let's follow the editor and take a look.

In fact, it is a problem of communication between windows. Open form2 on form1, and close form1 when form2 is closed

Implementation method:

Declare event in the child window form2:

public delegate void childclose();
  public event childclose closefather;

  然后在它的关闭事件中触发本事件:

   private void Form2_Closed(object sender, System.EventArgs e)
   {
    //用事件去关闭主窗口
    closefather();
   }
Copy after login

In the parent window form1 (such as the login window):

Then Where the sub-form2 form pops up, write this:

  Form2 ff=new Form2();
  ff.closefather+=new childclose(this.closethis); //closethis()是父窗体中的一个方法
  ff.Show();

   public void closethis()
   {
     this.Close();
   }
Copy after login

The above is the detailed content of C# case of closing child window and closing parent window. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template