Form Load Vs. Form Constructor


Can you please suggest what kind of code should be put in the Form Load event which cannot be put in the Form constructor?

Who is Participating?
Priest04Connect With a Mentor Commented:
Ahh, this one is very arguable one. I have read a lot about this, and still cant say anything with 100% certainity what is the best to do.

The basic difference is in Constructor form/controls are not yet visible, while during form load they are. Many people had problem when they wanted to close form while form_load was executing. If, for some reason, while in Form_load and fetching some data, something went wrong, and they wanted not to show the form, simple calling Form.Close method is not acceptable - it can cause memory leaks. This is one of the reasons why some folks dont recommend using Load event at all. :) They preffer to do it by overriding base OnLoad event. So, if something goes wrong, call base.OnLoad(), and close the form. So, using this tehnique you would never subscribe to Load event.

My advice would be to use conctructor for initialization stuff.

The Load event is called before the form is shown for the first time,
but after the form is constructed, so you know the child controls have been
created at this point.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.