winform窗体的生命周期和事件加载顺序是什么?

如题所述

  winform窗体的生命周期和事件加载顺序,如下:
  1.窗体启动:
  Control.HandleCreated
  Control.BindingContextChanged
  Form.Load
  Control.VisibleChanged
  Form.Activated
  Form.Shown  
  2.窗体关闭:
  Form.Closing
  Form.FormClosing
  Form.Closed
  Form.FormClosed
  Form.Deactivate  
  3.控件焦点与验证事件:
  Enter
  GotFocus
  Leave
  Validating
  Validated
  LostFocus  
  4.鼠标周期:
  Enter
  GotFocus
  LostFocus
  Leave
  Validating
  Validated
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2018-03-01
对于一个WinForm程序,如果是用VS自动创建的,那么程序的入口在这里

static class Program
{
/// <summary>
/// 应用程序的主入口点。
/// </summary>
[STAThread]
static void Main()
{
Application.EnableVisualStyles();
Application.SetCompatibleTextRenderingDefault(false);
Application.Run(new Form1());
}
}
}
最后一句,new Form1();调用了Form1的构造函数,而Form1的构造函数的内容是:
public Form1()
{
InitializeComponent();
}
调用了InitializeComponent();,这个函数内容是:
private void InitializeComponent()
{
this.components = new System.ComponentModel.Container();
this.label1 = new System.Windows.Forms.Label();
this.button1 = new System.Windows.Forms.Button();
this.notifyIcon1 = new System.Windows.Forms.NotifyIcon(this.components);
this.SuspendLayout();
//
// label1
//
this.label1.AutoSize = true;
this.label1.Location = new System.Drawing.Point(12, 9);
this.label1.Name = "label1";
this.label1.Size = new System.Drawing.Size(59, 12);
this.label1.TabIndex = 0;
this.label1.Text = "C#_Window";
//
// button1
//
this.button1.Location = new System.Drawing.Point(205, 238);
this.button1.Name = "button1";
this.button1.Size = new System.Drawing.Size(75, 23);
this.button1.TabIndex = 1;
this.button1.Text = "执行";
this.button1.UseVisualStyleBackColor = true;
this.button1.Click += new System.EventHandler(this.button1_Click);
//
// notifyIcon1
//
this.notifyIcon1.Text = "notifyIcon1";
this.notifyIcon1.Visible = true;
//
// Form1
//
this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 12F);
this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font;
this.ClientSize = new System.Drawing.Size(292, 273);
this.Controls.Add(this.button1);
this.Controls.Add(this.label1);
this.Name = "Form1";
this.Text = "Form1";
this.Load += new System.EventHandler(this.Form1_Load);
this.ResumeLayout(false);
this.PerformLayout();

}

窗体的控件定义如下:
private System.Windows.Forms.Label label1;
private System.Windows.Forms.Button button1;
private System.Windows.Forms.NotifyIcon notifyIcon1;本回答被提问者和网友采纳
相似回答