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