On Windows Forms, I have been doing initialization of values on Form_Load event handler. I use constructor mostly for make instances of member variables and setting basic/default values. I did the rest of the settings e.g: config, last state, on Form_Load. It turns out that it's not actually a best practice to do so.
I've just stumbled upon this discussion on Stack Overflow that explain that it is actually better to minimize the use of Load. In summary, here's the guideline on Constructor vs. Load issues :
- Initialize things on constructor
- Only use Load for code that needs valid windows handle e.g: code that requires the window size and location to be known
- Override OnLoad instead of using Form_Load event handler. This ensure more deterministic order of execution in relation to parents OnLoad call
No comments:
Post a Comment