您的位置:首页 > 其它

Windows 窗体应用程序中引发事件的顺序

2006-03-13 17:09 357 查看
对于关注对 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
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: