如何在加载或获取数据时取消关闭表单? [英] How to cancle the closing form when loading or fetch data?

查看:89
本文介绍了如何在加载或获取数据时取消关闭表单?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好,所有



目前,我正在学习vb.net,我正在学习关闭表单的代码,但是在表单处理和结束时遇到了一些问题,我的意思是我需要显示消息(请等待,提取数据将很快完成),如果进程尚未完成,如获取数据



注意:我的英语不是最强的



谢谢

kevin



我尝试了什么:



我需要了解更多信息,我希望这对新人来说是个好消息

Hi, all

Currently, I study vb.net, and I am learning the code about closing the form but I get some issue when form processing and closing, I mean I need to show the message( "please wait , fetching data will complete soon"), If the process not yet to complete such as fetching data

Note: my English not strongest

thank you
kevin

What I have tried:

I need learn more , I hope this will be good information for new guy

推荐答案

订阅表单的结束事件(WindowClosing或FormClosing)。它附带 CancelEventArgs ,其中包含取消属性。当你无法关闭表格时,将该属性设置为 True
Subscribe the Closing event (WindowClosing or FormClosing) of the form. It comes with CancelEventArgs which have a Cancel property. Set that property to True when you cannot close the form.


除了解决方案1:



处理 FormClosing 的替代方法,你可以覆盖虚方法 System.Windows.Forms.Form.FormClosing

https://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing%28v=vs.110%29.aspx



事件参数类型相同, FormClosingEventArgs ,因此您可以通过<$ c控制相同方式的处理取消$ c> FormClosingEventArgs.Cancel :

FormClosingEventArgs类(System.Windows.Forms) [ ^ ]。



注意你应该更好地检查 FormClosingEventArgs.CloseReason ;通常,只有在用户通过表单的控件关闭时才需要阻止关闭,所以你必须检查原因是 CloseReason.UserClosing

FormClosingEventArgs.CloseReason Property( System.Windows.Forms)

CloseReason Enumeration(System.Windows.Forms)



覆盖 FormClosing 对事件处理有一定的好处。原因如下:重写的代码更简单,更易于维护,创建派生类型的需求并不麻烦,因为Form类型通常都是在应用程序中派生的。



-SA
In addition to Solution 1:

An alternative to handling FormClosing, you can override the virtual method System.Windows.Forms.Form.FormClosing:
https://msdn.microsoft.com/en-us/library/system.windows.forms.form.onformclosing%28v=vs.110%29.aspx.

The event arguments type is the same, FormClosingEventArgs, so you control the cancellation of processing the same way, via FormClosingEventArgs.Cancel:
FormClosingEventArgs Class (System.Windows.Forms)[^].

Note the you should better check up FormClosingEventArgs.CloseReason; usually, you need to prevent closing only when it's closing by the user via the form's control, so you have to check is the reason is CloseReason.UserClosing:
FormClosingEventArgs.CloseReason Property (System.Windows.Forms),
CloseReason Enumeration (System.Windows.Forms).

Overriding FormClosing has certain benefits over the event handling. Here is why: overridden code is simpler and more maintainable, and the need to create a derived type is not a hassle, because Form types are usually derived in the application anyway.

—SA


这篇关于如何在加载或获取数据时取消关闭表单?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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