话不多说,直接展示
在主窗体中实例化子窗体
child child1=new child ();
关键步骤来了
child1.FormClosed+=closefather;
直接调用子窗体关闭窗体的事件,也就是进行一个委托
也可以自己写委托然后添加事件。原理是一样的。当按下子窗体的关闭按键时自动
会执行该事件,可以不用再写触发事件了,避免了代码冗余
最后别忘了在事件里面添加主窗体关闭的方法
private void closefather(object sender, EventArgs e)
{
this.Close();
this.Dispose();
}
结束