做了这么久桌面应用程序开发,对窗口的生命周期还没有一个清晰的了解。那我们就对*WinForm、WPF和ASP.NET*应用程序中窗口的生命周期做一个测试,看一下在窗口的创建和消亡的过程中,各个事件的执行顺序。
-
WinForm
首先,我们来看一下WinForm窗口。 在窗口的构造函数中注册一下各个事件。
this.HandleCreated += Form1_HandleCreated;
this.BindingContextChanged +=Form1_BindingContextChanged;
this.Load += Form1_Load;
this.VisibleChanged += Form1_VisibleChanged;
this.Activated += Form1_Activated;
this.Deactivate += Form1_Deactivate;
this.Shown += Form1_Shown;
this.FormClosing += Form1_FormClosing;
this.FormClosed +