Winforms - order of Load and Activated events

前端 未结 3 1584
渐次进展
渐次进展 2021-02-08 02:18

One of our users has sent in a log for our .NET Winforms application that indicates that the Activated event is occurring before the Load

3条回答
  •  不思量自难忘°
    2021-02-08 02:56

    From Order of Events in Windows Forms at MSDN:

    Application Startup and Shutdown Events

    The Form and Control classes expose a set of events related to application startup and shutdown. When a Windows Forms application starts, the startup events of the main form are raised in the following order:

    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

    When an application closes, the shutdown events of the main form are raised in the following order:

    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

    Are you using a MessageBox in any of your startup events? This can cause the events to appear to trigger out of order because of the way the Windows Forms Message Loop handles dialog windows.

提交回复
热议问题