在WinForms C#中使用Show()时如何检测窗口何时关闭 [英] How to detect when window is closed when using Show() in WinForms C#

查看:46
本文介绍了在WinForms C#中使用Show()时如何检测窗口何时关闭的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在以下列方式为我的所有新 Windows 使用 ShowDialog().

I've been using ShowDialog() in following way for all my new Windows.

SomeGui test = new SomeGui();
test.ShowDialog();
refreshSomeListView();

但是最近我开始使用 Show() 而不是 ShowDialog() 并且它工作得更好.唯一的缺点是 refreshSomeListView(); 不能像上面的例子那样使用,因为如果我把它留在那里,它会在新窗口出现时立即执行.

However recently I've started to use Show() instead of ShowDialog() and it's working much better. The only drawback of this is that refreshSomeListView(); cannot be used like in example above since if i leave it there it's executed instantly when new Window shows up.

知道用户已关闭 test 窗口并且现在应该执行 refreshSomeListView(); 的最佳方法是什么?对此有什么建议的方法?它应该涉及在关闭/关闭时在测试 GUI 中设置事件还是有其他/更好的方法?

What's the best way to know that the user has closed test window and that now refreshSomeListView(); should be executed? What's suggested approach for this? Should it involve setting events in test GUI on Close/Closing or there's other / better method?

推荐答案

您可以订阅 Form.Closed 事件并在其处理程序中执行刷新.这里 是此事件的 MSDN 描述.

You can subscribe to the Form.Closed event and perform refresh in its handler. Here is MSDN description of this event.

这篇关于在WinForms C#中使用Show()时如何检测窗口何时关闭的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆