Difference between Form1() and Form1_Load() ?

  • Thread starter Thread starter Carla Simeoni
  • Start date Start date
C

Carla Simeoni

In general I have two procedures which are called at the beginning of a Form:

Form1() { InitializeComponent(); ..... }

and

Form1_Load();

What is the difference ?

Which one is called at first ?

Where sould I put my own initialization statements ?

Carla
 
Form1() is constructor and Form1_Load() is an event called during the
load of Form1. Form1() is called first and shortly after that
Form1_Load() is called. Calls are made automatically. Proper way for
putting initialization statements would be to put them into
Form1_Load(), because if you put them in Form1() constructor Form
Designer can have some nasty results, like WSoD - "White Screen of
Death". I've seen this often done by my work colleague.

Carla Simeoni je napisao/la:
 
Form1() is constructor and Form1_Load() is an event called during the
load of Form1. Form1() is called first and shortly after that
Form1_Load() is called. Calls are made automatically. Proper way for
putting initialization statements would be to put them into
Form1_Load() [...]

Just to clarify, it depends on what sort of "initialization" statements
you're talking about.

As I understand it, the constructor is executed before the all of the
underlying Windows data has been initialized. The internal .NET stuff is
all there, but it's not all hooked up to Windows yet. So, you should wait
until the Load event to do anything that involves actually interacting
with Windows.

But for any sort of internal data initialization, the constructor is a
perfectly appropriate to do that. In fact, I'd argue that it's a more
appropriate place to do that, because the constructor is all about
*creating* the object, while the Load event is specifically for dealing
with things that have to be done as the control (a Form in this case) is
actually being displayed.

Pete
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top