其實是窗口間通訊的問題,在form1上打開form2 ,form2 關閉時關閉form1
實現方法:
在子窗口form2中聲明事件:
public delegate void childclose(); public event childclose closefather; 然后在它的關閉事件中觸發本事件: private void Form2_Closed(object sender, System.EventArgs e) { //用事件去關閉主窗口 closefather(); }
在父窗口form1中(比如登陸窗口中):
然后彈出子form2窗體的地方這樣寫:
Form2 ff=new Form2(); ff.closefather+=new childclose(this.closethis); //closethis()是父窗體中的一個方法 ff.Show(); public void closethis() { this.Close(); }
以上這篇c# 實現子窗口關閉父窗口也關閉的簡單實例就是小編分享給大家的全部內容了,希望能給大家一個參考,也希望大家多多支持VEVB武林網。
新聞熱點
疑難解答