表单构造函数对Form_Load [英] Form constructor vs Form_Load

查看:148
本文介绍了表单构造函数对Form_Load的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

表单构造函数和form_Load方法之间的区别是什么?

Whats the difference between a form constructor and the form_Load method?

将项目放在一个对象中的过程是什么?

Whats your though process for placing items in one vs the other?

推荐答案

在创建表单时,构造函数中的代码会立即运行,无论是否显示它。在 Form.Load 事件中运行的代码是一个事件处理程序,因此您可以在其他类(已订阅表单)中实际运行代码。同样,您可以(从表单)使用 Form.OnLoad方法运行代码。

Code in the constructor runs immediately when you create the form, whether or not you ever display it. Code running in the Form.Load event is an event handler, so you can actually have code in other classes (which have subscribed to the form) run code there. Similarly, you can (from the form) use the Form.OnLoad method to run code.

表单的Load事件(以及OnLoad overridable方法,通常是表单本身更好的选择)run后的表单已经初始化。这通常有优点,因为所有的窗体的控件已经构建,更重要的是,所有的窗体布局都已经发生了。

The form's Load event (and OnLoad overridable method, which is often a better choice in the form itself) runs after the form has been initialized. This often has advantages, since all of the form's controls have already been constructed, and more importantly, all of the form layout has occurred.

这篇关于表单构造函数对Form_Load的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆