为什么OnClosing过时,我应该迁移到OnFormClosing [英] Why is OnClosing obsolete and should I migrate to OnFormClosing

查看:206
本文介绍了为什么OnClosing过时,我应该迁移到OnFormClosing的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我读 MSDN文档为System.Windows.Forms.Form.OnClosing()方法,并注意到了:

I was reading the MSDN documentation for the System.Windows.Forms.Form.OnClosing() method and noticed:

注意:OnClosing方法已过时,在.NET Framework 2.0版;使用OnFormClosing方法来代替。

CAUTION: The OnClosing method is obsolete in the .NET Framework version 2.0; use the OnFormClosing method instead.

我找不到任何引用为为什么的它已被标记为过时。
我想我会在这里提问:

I can find no reference as to why it had been marked as obsolete.
I figured I would ask here:

  1. 在之前,我浪费了时间,通过反射耐劳
  2. 这将有作为参考他人有用

我看到的唯一区别是,你可以访问到的 FormClosingEventArgs 的,所以如果你不需要这些(你显然没有,如果你正在使用OnClosing),那么有没有什么好处切换到OnFormClosing?

The only difference I see is that you get access to the FormClosingEventArgs, so if you don't need those (which you obviously didn't if you were using OnClosing) then is there any benefit to switching to OnFormClosing?

据我所知,过时意味着它的可以的消失,所以你应该尽快更新,但你和我都知道,过时MS土地没什么意义。我想知道,雄厚的技术细节到的为什么的。

I understand that obsolete means that it could go away, so you should update as soon as possible, but you and I both know that obsolete in MS land means little. I want to know solid technical details as to why.

推荐答案

我认为主要的原因是为了解决一些与OnClosing的不一致,特别是事实,这是如果窗体正在关闭,由于没有叫Application.Exit。

I believe the main reason was to work around some of the inconsistencies with OnClosing, in particular, the fact that it is not called if the form is closing due to Application.Exit.

在<一个href="http://msdn.microsoft.com/en-us/library/system.windows.forms.form.onclosing.aspx">documentation:

在OnClosed和OnClosing方法不叫当应用.. ::。Exit方法被调用来退出你的应用程序。如果你有验证code在任一必须执行这些方法之前,您应该单独地调用exit方法调用的形式.. ::。Close方法为每个开放的形式。

The OnClosed and OnClosing methods are not called when the Application..::.Exit method is called to exit your application. If you have validation code in either of these methods that must be executed, you should call the Form..::.Close method for each open form individually before calling the Exit method.

的OnFormClosing提供对CloseReason构件,这使得处理更加容易正确地处理,在一个干净的,一致的方式

The OnFormClosing provides access to the CloseReason member, which makes the handling much easier to handle correctly, in a clean, consistent manner.

这篇关于为什么OnClosing过时,我应该迁移到OnFormClosing的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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