我是靠谱客的博主 虚拟诺言,这篇文章主要介绍Windows 窗体应用程序中引发事件的顺序,现在分享给大家,希望可以做个参考。

对于关注对 Windows 窗体应用程序中引发的每个事件按次序进行处理的开发人员来说,事件引发的顺序特别重要。当某种情况需要小心处理事件时(如重绘窗体的某些部分时),必须知道事件在运行时的确切引发顺序。

应用程序启动和关闭事件
Form 和 Control 类公开了一组与应用程序启动和关闭相关联的事件。当 Windows 窗体应用程序启动时,主窗体的启动事件按以下顺序引发:

System.Windows.Forms.Control.HandleCreated

System.Windows.Forms.Control.BindingContextChanged

System.Windows.Forms.Form.Load

System.Windows.Forms.Control.VisibleChanged

System.Windows.Forms.Form.Activated

System.Windows.Forms.Form.Shown

当应用程序关闭时,主窗体的关闭事件按以下顺序引发:

System.Windows.Forms.Form.Closing

System.Windows.Forms.Form.FormClosing

System.Windows.Forms.Form.Closed

System.Windows.Forms.Form.FormClosed

System.Windows.Forms.Form.Deactivate

Application 类的 ApplicationExit 事件在主窗体的关闭事件之后引发。


焦点和验证事件
当通过使用键盘(Tab、Shift+Tab 等等)、通过调用 Select 或 SelectNextControl 方法或通过设置当前窗体的 P:System.Windows.Forms.ContainerControl.ActiveControl 属性更改焦点时,Control 类的焦点事件按以下顺序发生:

Enter

GotFocus

Leave

Validating

Validated

LostFocus

当通过使用鼠标或通过调用 Focus 方法更改焦点时,Control 类的焦点事件按以下顺序发生:

Enter

GotFocus

LostFocus

Leave

Validating

 

最后

以上就是虚拟诺言最近收集整理的关于Windows 窗体应用程序中引发事件的顺序的全部内容,更多相关Windows内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(117)

评论列表共有 0 条评论

立即
投稿
返回
顶部