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(); }
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(); }
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!