How to detect when window is closed when using Show() in WinForms C#

半腔热情 提交于 2019-12-11 14:47:37

问题


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

SomeGui test = new SomeGui();
test.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.

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?


回答1:


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




回答2:


In VB.Net:

Dim test as new SomeGui()
AddHandler test.Closed, AddressOf refreshSomeListView
test.Show


来源:https://stackoverflow.com/questions/2462105/how-to-detect-when-window-is-closed-when-using-show-in-winforms-c-sharp

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!