.net - Winforms - Load 和 Activated 事件的顺序

标签 .net winforms events load

我们的一位用户发送了我们 .NET Winforms 应用程序的日志,表明 Activated事件正在发生 之前 Load事件。我不认为这是可能的,并假设 Load 进行编码。总是会在 Activated 之前发生.

有没有其他人观察到Activated发生在 Load 之前?

如果是这样,为什么以及有什么方法可以确保它不会发生?

最佳答案

来自 Order of Events in Windows Forms在 MSDN:

Application Startup and Shutdown Events

The Form and Control classes expose a set of events related to application startup and shutdown. When a Windows Forms application starts, the startup events of the main form are raised in the following order:

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

When an application closes, the shutdown events of the main form are raised in the following order:

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



您是否在任何启动事件中使用 MessageBox?由于 Windows 窗体消息循环处理对话框窗口的方式,这可能会导致事件显示为无序触发。

关于.net - Winforms - Load 和 Activated 事件的顺序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1430955/

相关文章:

c# - 使用openxml将背景颜色应用于excel中的特定单元格

javascript - 同时点击2个元素?

c# - .NET 中的 Web 浏览器。浏览器设置

c# - 为什么 HttpClient 没有在浏览器中打开任何页面?

vb.net - 以编程方式设置 ListView 中的所选项目后,箭头键不起作用

c# - 是否可以像 WebView 一样在 Windows 窗体中嵌入 Gecko 或 Webkit?

c# - 应用程序设置可靠吗?

c# - 自处理事件是否会阻止实例被垃圾收集?

iphone - 监听 TabBar View 变化

c# - 警告用户 .NET Framework 要求