开发者

In what order do .NET Windows forms events fire?

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.


This is one of the relevant pages on MSDN :

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


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


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


I have seen this behavior, may have something to do with 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

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜