views:

596

answers:

3

I notice that there are a number of different events I can capture when I'm working with a Windows Form in .NET (or any other control, for that matter) - on opening, there's:

  • Load
  • Activated
  • Shown
  • VisibleChanged

And when closing, there's:

  • Leave
  • FormClosed
  • FormClosing
  • Disposed

Plus any others I've missed. I know I could put a messagebox in each event, and then run my application and write down the order, but I doubt I'll remember it.

Is there a reference online that lists the -order- in which these events occur, for Forms and other controls? I can't find it on MSDN, though maybe I've missed it somewhere.

+2  A: 

This is one of the relevant pages on MSDN :

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

CodeByMoonlight
Wow - my Google skills are weak. I can't believe I missed that.
rwmnau
+3  A: 

This is also called the lifecycle of win-forms applications. Every .net technology has a document on these.

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

Form Startup

  1. OnHandleCreated
  2. OnCreateControl
  3. OnLoad
  4. OnActivated
  5. OnShown

Form Shutdown

  1. OnClosing
  2. OnClosed
  3. OnDeactivate
  4. OnHandleDestroyed
Shawn Mclean
+1 for mentioning "lifecycle" - knowing the magic keyword is a huge help when searching
overslacked
+1  A: 

Showing a form:

  1. Control.HandleCreated
  2. Control.BindingContextChanged
  3. Form.Load
  4. Control.VisibleChanged
  5. Control.GotFocus
  6. Form.Activated
  7. Form.Shown

Closing a form:

  1. Form.Closing
  2. Form.FormClosing
  3. Form.Closed
  4. Form.FormClosed
  5. Form.Deactivate
  6. Control.LostFocus
  7. Control.HandleDestroyed
  8. Component.Disposed
Patrik