加载,的OnLoad,构造 [英] Load, OnLoad, Constructor

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

问题描述

从我读过它看起来像使用覆盖到的onLoad是一种更好的方式去,而不是在构造初步处理方法等做题..

From other SO questions that I have read it seems like using an override to onLoad is a better way to go instead of handling initial methods in the constructor..

什么,当我把破发点,在我的代码,我发现的是,在onLoad方法得到击中,但构造函数是不是..我的形式显然是被打开罚款,所以我想知道是否有人能任何光线进入棚的顺序,这些发生?

What I'm finding when I put break points into my code is that the onLoad method is getting hit but the constructor isn't.. my form is obviously being opened fine so I'm wondering if anyone is able to shed any light into the order in which these happen?

这是一个自定义加载事件也

This is the same for a custom load event also

相同修改:白痴就是为什么我的断点没有被击中的原因,但我还是有点困惑,当负载覆盖被称为

EDIT: idiocy is to the reason why my breakpoint wasn't getting hit but I'm still a little confused as to when the on load override is called?

推荐答案

在onload方法/正在显示的形式首次在执行的事件。

The OnLoad method/event is executed when the form is being shown for the first time.

当你使用new关键字来创建窗体类的新实例构造函数总是被调用。

The constructor is always called when you use the new keyword to create a new instance of your Form's class.

人们普遍认为这样做在构造函数中的所有形式的初始化最佳实践,而不是过程中的OnLoad。如果你有一个以上的构造函数,并要在所有这些执行一些常见初始化任务,把它们放在一个单独的方法,并从你的构造函数调用它。确保的InitializeComponent()被称为构造函数的一部分。的OnLoad真的应该,如果你需要重新定位您的形式或事情才能使用。

It is generally considered best practice to do all form initialization within the constructor, and not during OnLoad. If you have more than one constructor and want to perform some common initialization tasks within all of them, put them in a separate method and call it from your constructor. Make sure InitializeComponent() is called as part of your constructor. OnLoad should really only be used if you need to re-position your form or something.

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

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