The following small series for everyone to bring a C # implementation child window close the parent window is also closed a simple instance. Small series feel very good, now share to everyone, also for everyone to make a reference. Let's take a look at it with a little knitting.
is actually the problem of inter-window communication, open Form2 on Form1, Form2 close Form1
Implementation method:
To declare an event in the child window Form2:
public delegate void Childclose (); public event Childclose Closefather; This event is then triggered in its Shutdown event: private void Form2_closed (object sender, System.EventArgs e) { //use event to close the main window Closefather (); }
In the parent window Form1 (such as in the login window):
Then pop up the sub-Form2 form where this is written:
Form2 ff=new Form2 (); Ff.closefather+=new Childclose (this.closethis); Closethis () is a method ff in the parent form . Show (); public void Closethis () {this . Close (); }