最新下载
热门教程
- 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(); } | |
相关文章
- 126邮箱快捷登录入口-126邮箱网页版一键免费登录 05-28
- 《镭明闪击》第四章通关全流程详解-指挥官等级与战术专精攻略 05-28
- 爱剪辑怎么转码 05-28
- 卡厄思梦境蕾诺娅如何 卡厄思梦境蕾诺娅分享 05-28
- 逆战手游冥河之矛插件如何搭配 05-28
- 卡厄思梦境光谱方块是什么 卡厄思梦境光谱方块分享 05-28