winform常用参考:
C# 常用控件及单击事件
Windows 窗体中的事件顺序(microsoft官方说明)
以下内容来自网络梳理总结:
Load:会执行两次。所以在load事件中如果你使用了Dictionary<>集合 。会一直报错说添加了重复键
Initialized:一来就加载
WPF 中的 loaded 事件和 Initialized 事件
public partial class TestForm : Form
{
public TestForm()
{
Console.WriteLine(1);
InitializeComponent();
Console.WriteLine(2);
}
protected override void OnLoad(EventArgs e)
{
Console.WriteLine(3);
base.OnLoad(e);
Console.WriteLine(4);
}
protected override void OnCreateControl()
{
Console.WriteLine(5);
base.OnCreateControl();
Console.WriteLine(6);
}
protected override void OnShown(EventArgs e)
{
Console.WriteLine(7);
base.OnShown(e);
Console.WriteLine(8);
}
protected override void OnActivated(EventArgs e)
{
Console.WriteLine(9);
base.OnActivated(e);
Console.WriteLine(10);
}
protected override void OnClientSizeChanged(EventArgs e)
{
Console.WriteLine(11);
base.OnClientSizeChanged(e);
Console.WriteLine(12);
}
protected override void OnGotFocus(EventArgs e)
{
Console.WriteLine(13);
base.OnGotFocus(e);
Console.WriteLine(14);
}
protected override void OnResize(EventArgs e)
{
Console.WriteLine(15);
base.OnResize(e);
Console.WriteLine(16);
}
}
结果:
1
2
5
3
4
6
13
14
9
10
7
8