Winforms Form构造函数vs加载事件 [英] Winforms Form Constructor vs Load event

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

问题描述

加载表单时,代码需要执行的操作包括设置datagrids,组合框,设置标题等。我倾向于总是使用load事件,而不是新的(构造函数)。

When a form loads, the code needs to do things like setup datagrids, comboboxes, set the title, etc. I've tended to always use the load event rather than the new (constructor). Are there any guidelines for which one is best for which activities?

推荐答案

请注意,表单构造函数中的任何内容都将在创建表单时创建/执行。即在:

Bear in mind that anything in the constructor of a form will be created/executed at that forms creation. i.e. at:

表单frm = new Form();

Form frm = new Form();

当表单显示
frm.Show();

Whereas anything in the Load event will occur only when the form is shown i.e. frm.Show();

这篇关于Winforms Form构造函数vs加载事件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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