Form Load Vs. Form Constructor

Posted on 2007-08-03
Last Modified: 2010-04-15

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

Question by:rajesh_khater
    LVL 8

    Expert Comment

    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.
    LVL 18

    Accepted Solution

    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.


    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Join & Write a Comment

    In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
    Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
    how to add IIS SMTP to handle application/Scanner relays into office 365.
    Internet Business Fax to Email Made Easy - With eFax Corporate (, you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…

    755 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

    Need Help in Real-Time?

    Connect with top rated Experts

    20 Experts available now in Live!

    Get 1:1 Help Now