Re: Difference between Form1() and Form1_Load() ?

Tech-Archive recommends: Repair Windows Errors & Optimize Windows Performance



On Fri, 25 May 2007 02:04:08 -0700, Miroslav Stampar <miroslav.stampar@xxxxxxxxx> wrote:

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
.



Relevant Pages

  • Winforms and SQL Threading Problem
    ... I have a big issue with threading in Windows Forms. ... I make this Form1 as MdiContainer. ... In the Load Event I create a new thread and after this I ... private void Form1_Load ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Keeping invisible forms from showing at start-up
    ... > Paul E. Schoen wrote: ... >> The following code is part of my Delphi project file: ... Application.Terminate in Form1, after doing some clean-up. ... I thought this was done at initialization if explicitly set in Project ...
    (comp.lang.pascal.delphi.misc)
  • Re: How to eliminate Tiling of windows forms background images
    ... Please excuse my stupidity but I upgraded my vb6 program to ... the Form1 load event I use the following procedure to get ... I used the following procedure to load the file as ... suggestion I consider overriding the OnPaintBackground method and I am ...
    (microsoft.public.dotnet.general)
  • IDE failing to load Form2 when inheriting from Form1 containing user control
    ... inherited form into the IDE from a base form when I add items to an ... All this appears to work ok and I can put the control on Form1 and add ... However if I now create a Form2 and inherit from Form1 I get the ... following message when trying to load Form2 into the IDE: ...
    (microsoft.public.dotnet.languages.csharp)
  • Re: Timer
    ... In this instance Form1 is the main form for you application. ... private void timer1_Tick(object sender, System.EventArgs e) ... But, instead, you could load Form1, but have it's Visible property set to ...
    (microsoft.public.dotnet.languages.csharp)