首页 > 编程 > C# > 正文

c# 实现子窗口关闭父窗口也关闭的简单实例

2019-10-29 21:13:26
字体:
来源:转载
供稿:网友

其实是窗口间通讯的问题,在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武林网。


注:相关教程知识阅读请移步到c#教程频道。
发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表