c# 实现子窗口关闭父窗口也关闭的简单实例
其实是窗口间通讯的问题,在form1上打开form2,form2关闭时关闭form1
实现方法:
在子窗口form2中声明事件:
publicdelegatevoidchildclose();
publiceventchildcloseclosefather;
然后在它的关闭事件中触发本事件:
privatevoidForm2_Closed(objectsender,System.EventArgse)
{
//用事件去关闭主窗口
closefather();
}
在父窗口form1中(比如登陆窗口中):
然后弹出子form2窗体的地方这样写:
Form2ff=newForm2();
ff.closefather+=newchildclose(this.closethis);//closethis()是父窗体中的一个方法
ff.Show();
publicvoidclosethis()
{
this.Close();
}
以上这篇c#实现子窗口关闭父窗口也关闭的简单实例就是小编分享给大家的全部内容了,希望能给大家一个参考,也希望大家多多支持毛票票。