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
应用程序启动和关闭事件
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窗体中的事件顺序
- Windows窗体应用程序常用的几个类的属性、方法以及事件
- Windows 窗体计时器事件,则不引发在 Windows 服务
- Windows 窗体启动和关闭的事件顺序
- Windows 窗体中的事件顺序
- Windows 窗体中的事件顺序
- Windows 窗体启动和关闭的事件顺序
- Windows 窗体中的事件顺序
- Windows 窗体启动和关闭的事件顺序
- 关于 OnCloseQuery: 顺序、不能关机等(所有的windows的广播消息都是逐窗口传递的)——如果一个窗体的OnCloseQuery事件中如果写了代码那么WM_QUERYENDSESSION消息就传不过去了msg.result会返回0,关机事件也就停止了
- Windows 窗体启动和关闭的事件顺序
- Windows 窗体启动和关闭的事件顺序
- Windows 窗体启动和关闭的事件顺序
- Windows 窗体中的事件顺序
- Windows 窗体计时器事件,则不引发在 Windows 服务
- 在 Visual C# .NET 中处理 Windows 窗体中 Office XP 电子表格组件的事件
- 使用 ClickOnce 部署 Windows 窗体应用程序
- C#学习笔记四 Windows窗体应用程序
- C# 窗体运用程序加载,事件触发顺序