开发者

WinForms event life cycle

Just like there is Page life cycle in web 开发者_开发百科applications, what is the event life cycle for WinForms, especially between Form and User Controls?


According to MSDN:

Startup events of the main form are raised in the following order:

Control.HandleCreated
Control.BindingContextChanged
Form.Load
Control.VisibleChanged
Form.Activated
Form.Shown

Shutdown events of the main form are raised in the following order:

Form.Closing
Form.FormClosing
Form.Closed
Form.FormClosed
Form.Deactivate
Application.ApplicationExit *

I'm aware this is an old question, but I thought I'd include an actual answer since most are mere links.


FWIW, you should be careful about making life-cycle assumptions about some container controls. For example, in a tab control, I believe the controls on the second and later tabs are lazy loaded. The controls on those tabs may not be instantiated/initialized until the first visit to the tab, so, form level code should not assume that all controls on all tab pages are in place at the completion of form loading.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜