c#中委托与事件的使用-以winform中跨窗体传值为例:
https://blog.csdn.net/badao_liumang_qizhi/article/details/100150700
参考上面的博客。
需求是在图形选项窗体中刷新主窗体的图。
注:
博客主页:
关注公众号
霸道的程序猿
获取编程相关电子书、教程推送与免费下载。
首先是图形选项窗体,即发起方。
先要声明刷新事件(此事件声明在图形选项工具类datacharthelper中):
public static event eventhandler onrefreshchart;
然后图形选项窗体的保存按钮事件中要调用刷新事件时需要触发:
if (this.confirm("保存成功") == dialogresult.ok) { common.datachart.datacharthelper.triggerrefreshchart(); //触发图形刷新事件 this.dispose(); }
此时会触发在图形选项工具类中的triggerrefreshchart(),回到工具类中:
public static void triggerrefreshchart() { if (onrefreshchart != null) { onrefreshchart(null, system.eventargs.empty); } }
此时需要在主页面进行图的刷新。在主页面窗体的窗体加载事件中进行事件订阅:
common.datachart.datacharthelper.onrefreshchart -= datacharthelper_onrefreshchart; common.datachart.datacharthelper.onrefreshchart += datacharthelper_onrefreshchart;
此时就会执行当前主页面的方法datacharthelper_onrefreshchart:
private void datacharthelper_onrefreshchart(object sender, eventargs e) { datacharthelper.refreshpane(this.zedgraphcontrol1); }
此方法会执行具体的操作,具体操作是调用工具类中的刷新方法。
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
网友评论