c# windows form 生命周期 (Life cycle) 事件 顺序
2012-05-16 14:38
429 查看
c# windows form 生命周期 (Life cycle) 事件 顺序 窗口 初始化
____________________________________________________________________________________________________________________
微软官方的文档:
form 打开:
• Control.HandleCreated
• Control.BindingContextChanged
• Form.Load
• Control.VisibleChanged
• Form.Activated
• Form.Shown
from 关闭:
• Form.Closing
• Form.FormClosing
• Form.Closed
• Form.FormClosed
• Form.Deactivate
control ,change focus:(使用 tab ,shift + tab等等,或是调用Select,SelectNextControl,或是使用当前form的ActiveControl)
• Enter
• GotFocus
• Leave
• Validating
• Validated
• LostFocus
control ,change focus:(使用鼠标,或是通过调用Focus方法)
• Enter
• GotFocus
• LostFocus
• Leave
• Validating
• Validated
____________________________________________________________________________________________________________________
//z 2012-5-16 14:41:02 PM IS2120@CSDN
Move,Load,VisibleChanged 以及 Activated 事件在form显示之前就触发了。
事件的含义:
Move: This event occurs when the form is moved. Although by default, when a form is instantiated and launched, the user does not move it, yet this event is triggered before the Load event occurs.
Load: This event occurs before a form is displayed for the first time.
VisibleChanged: This event occurs when the Visible property value changes.
Activated: This event occurs when the form is activated in code or by the user.
Shown: This event occurs whenever the form is first displayed.
Paint: This event occurs when the control is redrawn.
Deactivate: This event occurs when the form loses focus and is not the active form.
Closing: This event occurs when the form is closing.
Closed: This event occurs when the form is being closed.
b. Activated: fired whenever the form gets the focus i.e. when loaded first time, restored from the minimize state, whenever the form is brought in front.
c. Deactivated: fired whenever the form looses focus i.e. when form is closed, minimized, when it is in background.
d. Closing: Triggered when application wishes to be closed.
e. Closed: Triggered when application is closed.
f. Disposed: Used for garbage collection.
事件的顺序:
Form Events:
Construtor
Load
Layout
Activated
Paint
Closing
Closed
Deactivate
Dispose
and for Controls:
Enter
GotFocus
Leave
Validating
Validated
LostFocus
另一个版本的form event 顺序
Load
VisibleChanged
Activated
Shown
Paint
Deactivate
Activated
Paint
Formclosing
FormClosed
Deactivate
//z 2012-5-16 14:41:02 PM IS2120@CSDN
Form Startup
OnHandleCreated
OnCreateControl
OnLoad
OnActivated
OnShown
Form Shutdown
OnClosing
OnClosed
OnDeactivate
OnHandleDestroyed
____________________________________________________________________________________________________________________
微软官方的文档:
form 打开:
• Control.HandleCreated
• Control.BindingContextChanged
• Form.Load
• Control.VisibleChanged
• Form.Activated
• Form.Shown
from 关闭:
• Form.Closing
• Form.FormClosing
• Form.Closed
• Form.FormClosed
• Form.Deactivate
control ,change focus:(使用 tab ,shift + tab等等,或是调用Select,SelectNextControl,或是使用当前form的ActiveControl)
• Enter
• GotFocus
• Leave
• Validating
• Validated
• LostFocus
control ,change focus:(使用鼠标,或是通过调用Focus方法)
• Enter
• GotFocus
• LostFocus
• Leave
• Validating
• Validated
____________________________________________________________________________________________________________________
//z 2012-5-16 14:41:02 PM IS2120@CSDN
Move,Load,VisibleChanged 以及 Activated 事件在form显示之前就触发了。
事件的含义:
Move: This event occurs when the form is moved. Although by default, when a form is instantiated and launched, the user does not move it, yet this event is triggered before the Load event occurs.
Load: This event occurs before a form is displayed for the first time.
VisibleChanged: This event occurs when the Visible property value changes.
Activated: This event occurs when the form is activated in code or by the user.
Shown: This event occurs whenever the form is first displayed.
Paint: This event occurs when the control is redrawn.
Deactivate: This event occurs when the form loses focus and is not the active form.
Closing: This event occurs when the form is closing.
Closed: This event occurs when the form is being closed.
Explain the key events in the lifecycle of the form.
a. Load: fired when form is first loaded in the applicationb. Activated: fired whenever the form gets the focus i.e. when loaded first time, restored from the minimize state, whenever the form is brought in front.
c. Deactivated: fired whenever the form looses focus i.e. when form is closed, minimized, when it is in background.
d. Closing: Triggered when application wishes to be closed.
e. Closed: Triggered when application is closed.
f. Disposed: Used for garbage collection.
事件的顺序:
Form Events:
Construtor
Load
Layout
Activated
Paint
Closing
Closed
Deactivate
Dispose
and for Controls:
Enter
GotFocus
Leave
Validating
Validated
LostFocus
另一个版本的form event 顺序
Load
VisibleChanged
Activated
Shown
Paint
Deactivate
Activated
Paint
Formclosing
FormClosed
Deactivate
//z 2012-5-16 14:41:02 PM IS2120@CSDN
Form Startup
OnHandleCreated
OnCreateControl
OnLoad
OnActivated
OnShown
Form Shutdown
OnClosing
OnClosed
OnDeactivate
OnHandleDestroyed
相关文章推荐
- c# windows form 生命周期 (Life cycle) 事件 顺序
- C#WindowsForm拖拽事件一例bug分析
- C#Windows控件的焦点事件顺序
- C# Windows Forms 事件处理顺序
- c#中如何截取Windows消息来触发自定义事件
- C#页面加载 , 事件顺序
- C#的WINDOWS应用程序(FORM)怎样接收命令行调用和参数
- form表单中onclick事件和onsubmit事件的执行顺序
- C#中Form的Paint事件响应方法与重载虚方法OnPaint()的区别
- ASP.NET 页面事件顺序和生命周期
- 使用c#捕获windows的关机事件
- WinForm-Windows控件的焦点事件顺序
- C# Adding Hyperlink to Windows Form z
- asp.net中page对象生命周期和各事件执行顺序
- 使用c#捕获windows的关机事件
- C#windowsform去掉GroupBox边框
- 关于C# Windows 程序设计里的button click事件的分析
- 马牛的C#学习(第四天)-从windows应用程序理解OOP|定义类|构造函数的执行顺序
- Asp.net(C#) windows 服务{用于实现计划任务,事件监控等}
- 使用c#捕获windows的关机事件