WinForm载入窗体完成后自动执行事件
当 Windows Form 应用程序启动时,会以下列顺序引发主要表单的启动事件:
System.Windows.Forms.Control.HandleCreated
System.Windows.Forms.Control.BindingContextChanged
System.Windows.Forms.Form.Load
System.Windows.Forms.Control.VisibleChanged
System.Windows.Forms.Form.Activated
System.Windows.Forms.Form.Shown
当应用程序关闭时,会以下列顺序引发主要表单的关闭事件:
System.Windows.Forms.Form.Closing
System.Windows.Forms.Form.FormClosing
System.Windows.Forms.Form.Closed
System.Windows.Forms.Form.FormClosed
System.Windows.Forms.Form.Deactivate
在Form1_Load之后自动执行事件
可以使用事件Form1_Activated或Form1_Shown
区别在于Form1_Activated先执行。Form1_Activated可能触发多次。
Form1_Shown是所有控件加载完成后执行,只会触发一次。如果控件设置了背景图片,那么控件的背景颜色是不显示的。
public bool IsActivated = false;
private void Form1_Activated(object sender, EventArgs e)
{textBox1.Text += "Form1_Activated" + System.Environment.NewLine;if (!IsActivated){IsActivated = true;panel2.Dock = DockStyle.Fill;}
}private void Form1_Shown(object sender, EventArgs e)
{textBox1.Text += "Form1_Shown" + System.Environment.NewLine;
}
msdn参考https://msdn.microsoft.com/zh-cn/library/86faxx0d.aspx
本文来自互联网用户投稿,文章观点仅代表作者本人,不代表本站立场,不承担相关法律责任。如若转载,请注明出处。 如若内容造成侵权/违法违规/事实不符,请点击【内容举报】进行投诉反馈!
