winform窗体的生命周期和事件加载顺序是啥?
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了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 参考技术A 对于一个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;本回答被提问者和网友采纳
winform 窗体加载时间过长 在load事件中,要初始化很多控制的数据源。导致页面显示出来很慢,求方法
参考技术A 可以写在构造函数里边吧。 一少部分写在窗体加载事件中。 参考技术B 可采用多线程方式,后台数据独立开启一个子线程进行加载,这样便不会影响的ui线程了。以上是关于winform窗体的生命周期和事件加载顺序是啥?的主要内容,如果未能解决你的问题,请参考以下文章