Learn how to a build a cloud-first strategyRegister Now

x
?
Solved

Form Load Vs. Form Constructor

Posted on 2007-08-03
5
Medium Priority
?
204 Views
Last Modified: 2010-04-15
Hi,

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

Thanks.
0
Comment
Question by:rajesh_khater
2 Comments
 
LVL 8

Expert Comment

by:sabeesh
ID: 19625756
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.
0
 
LVL 18

Accepted Solution

by:
Priest04 earned 2000 total points
ID: 19627604
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.

Goran
0

Featured Post

Prep for the ITIL® Foundation Certification Exam

December’s Course of the Month is now available! Enroll to learn ITIL® Foundation best practices for delivering IT services effectively and efficiently.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Is your OST file inaccessible, Need to transfer OST file from one computer to another? Want to convert OST file to PST? If the answer to any of the above question is yes, then look no further. With the help of Stellar OST to PST Converter, you can e…
Suggested Courses
Course of the Month20 days, 18 hours left to enroll

810 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question