WinForms event life cycle

后端 未结 2 1434
长发绾君心
长发绾君心 2020-12-29 06:31

Just like there is Page life cycle in web applications, what is the event life cycle for WinForms, especially between Form and User Controls?

相关标签:
2条回答
  • 2020-12-29 07:25

    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 讨论(0)
  • 2020-12-29 07:30

    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.

    0 讨论(0)
提交回复
热议问题