In what order are the .NET Windows events triggered?

I notice that there are several different events that I can capture when I work with Windows Form in .NET (or any other control, for that matter) - when opened, there is:

  • Load
  • Activated
  • Shown
  • Visiblechanged

And at closing there is:

  • Leave
  • Formclosed
  • Formclosing
  • Disposed

Plus any others I missed. I know that I can put messages in every event, and then run my application and record the order, but I doubt that I will remember it.

Is there an online link that lists the -order- options in which these events occur for forms and other controls? I can not find it on MSDN, although maybe I missed it somewhere.

+4
source share
4 answers

This is one of the relevant pages on MSDN:

http://msdn.microsoft.com/en-us/library/86faxx0d.aspx

+7
source

This is also called the win-forms application lifecycle. Each .net technology has a document on them.

Winforms - http://blogs.msdn.com/jaredpar/archive/2007/01/08/windows-forms-event-lifecycle.aspx

Form launch

  • Onhandlecreated
  • Oncreatecontrol
  • Onload
  • Onactivated
  • Onshown

Closing form

  • Onclosing
  • Onclosed
  • Ondeactivate
  • Onhandledestroyed
+7
source

Form Display:

  • Control.HandleCreated
  • Control.BindingContextChanged
  • Form.load
  • Control.VisibleChanged
  • Control.GotFocus
  • Form.Activated
  • Form.Shown

Closing the form:

  • Form.Closing
  • Form.FormClosing
  • Form.Closed
  • Form.FormClosed
  • Form.Deactivate
  • Control.LostFocus
  • Control.HandleDestroyed
  • Component.Disposed
+2
source

I saw this behavior, maybe something related to MDI:

form.Focus(); // calls OnHandleCreated (this.Handle is x) form.Show( ); // calls OnLoad (this.Handle is still x), then OnHandleCreated (this.Handle is y) 
0
source

All Articles