最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
c# 实现子窗口关闭父窗口也关闭的简单实例
时间:2022-06-25 07:52:24 编辑:袖梨 来源:一聚教程网
其实是窗口间通讯的问题,在form1上打开form2 ,form2 关闭时关闭form1
实现方法:
在子窗口form2中声明事件:
| 代码如下 | 复制代码 |
publicdelegatevoidchildclose(); publiceventchildclose closefather;
然后在它的关闭事件中触发本事件:
privatevoidForm2_Closed(objectsender, System.EventArgs e) { //用事件去关闭主窗口 closefather(); } | |
在父窗口form1中(比如登陆窗口中):
然后弹出子form2窗体的地方这样写:
| 代码如下 | 复制代码 |
Form2 ff=newForm2(); ff.closefather+=newchildclose(this.closethis);//closethis()是父窗体中的一个方法 ff.Show();
publicvoidclosethis() { this.Close(); } | |
相关文章
- 如何查看软件商店忽略列表 03-30
- 网易云音乐如何清除听歌记录 03-30
- 悟空浏览器如何一键打开网页-悟空浏览器电脑版在线免费观看 03-30
- 漫画网址资源下载入口在哪最新版安装教程-漫画网址下载热门站点汇总免费高清版 03-30
- QQ音乐如何添加本地歌曲 03-30
- 网易云音乐怎么设置状态 03-30