c# 实现子窗口关闭父窗口也关闭的方法

下面小编就为大家带来一篇c# 实现子窗口关闭父窗口也关闭的方法。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧

其实是窗口间通讯的问题,在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# 实现子窗口关闭父窗口也关闭的方法的详细内容,更多请关注0133技术站其它相关文章!

赞(0) 打赏
未经允许不得转载:0133技术站首页 » 其他教程