473,323 Members | 1,547 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,323 software developers and data experts.

Difference between Form1() and Form1_Load() ?

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

May 25 '07 #1
2 14416
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:
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
May 25 '07 #2
On Fri, 25 May 2007 02:04:08 -0700, Miroslav Stampar
<mi**************@gmail.comwrote:
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
May 25 '07 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

5
by: w i l l | last post by:
Why does this work the way it does? If someone could explain return true, and return false to me I'd greatly appreciate it. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> ...
0
by: | last post by:
I have been learning really hard to understand this .NET security thing, but I still get overwhelmed with the abstractness. The hardest part is to understand *when* you get an SecurityException and...
6
by: deko | last post by:
Is there a difference between the Form_Open and Form_Load events? When should I use one rather than the other? I have several forms that require code to run when they open... or is it when they...
3
by: polarz | last post by:
I'm having trouble getting items from different classes to display in my textBox. e.g. private void button2_Click(object sender, System.EventArgs e) { someData sd = new someData();...
5
by: nadir b | last post by:
hi I don't know how to change for exemple a form1 caption text from form2 don't forget that form2 has created from form1 I want sample code with c# *** Sent via Developersdex...
3
by: Jon Natwick | last post by:
This "Countdown Timer" code works fine with Ie, but I receive an "Error: Form1 is not defined" error with Firefox 1.0.0 and 1.0.1. <body MS_POSITIONING="FlowLayout" onload="InitializeTimer()">...
12
by: Nathan Sokalski | last post by:
What is the difference between the Page_Init and Page_Load events? When I was debugging my code, they both seemed to get triggered on every postback. I am assuming that there is some difference,...
11
by: chopsnsauce | last post by:
Here's the example: Dim frm As New FORM1 Try frm.show Catch ex As Exception msgbox ex.message
2
by: Jamey Bon | last post by:
I am a C# newbie. I am having a tough time with several issues of scope and visibility. In short, why can't I see any of the elements of Form1 (the base form generated by the "Windows...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.