0

In Visual Studio C# Windows form application, what is the deferent between class constructor and form load?

Da Xiong
  • 135
  • 2
  • 9
  • a class may have multiple constructors that take different arguments, a form load, just simply loads the form on the screen and loads once the as the form is being loaded – Apollo SOFTWARE Mar 27 '14 at 09:45
  • Possible duplicate of [What setup code should go in Form Constructors versus Form Load event?](http://stackoverflow.com/questions/2521322/what-setup-code-should-go-in-form-constructors-versus-form-load-event) – Jim Fell May 11 '16 at 13:53
  • Possible duplicate of [Winforms Form Constructor vs Load event](http://stackoverflow.com/questions/264396/winforms-form-constructor-vs-load-event) – Jim Fell Jul 07 '16 at 14:36

5 Answers5

3

Well simply put the constructor is called when the class is instantiated like all constructors, while the page load is called whenever a form is displayed for the first time.

http://msdn.microsoft.com/en-us/library/system.windows.forms.form.load(v=vs.110).aspx

Murdock
  • 3,722
  • 1
  • 24
  • 50
0

a class may have multiple constructors that take different arguments, a form load, just simply loads the form on the screen and loads once the as the form is being loaded.

You can instantiate a class from your form load if you want to.

Apollo SOFTWARE
  • 11,420
  • 4
  • 41
  • 61
0

Question looks a bit odd for me, You can't compare apples with oranges.

Constructor is a method which will be executed when you instantiate an object where as Form.Load is an event.

btw Form.Load will only fired before the form is about to render into the screen; typically Form.Show causes Form.Load event.

Sriram Sakthivel
  • 67,773
  • 7
  • 96
  • 172
0

Form.onLoad is an event, which occurs, when the form is shown on the screen. One can attach an eventhandler to this event and react inside it.

The constructor instantiates the (form)class, a public method without any return value ( even without null ). It MUST (MOSTLY) be called PRIOR to any "show" or "showdialog" method, so that the event "onLoad" may occurr ( in fact any "show" related methods are the reasons, why the event "onLoad" is fired).

If the constructor is not called, mostly onLoad will never occur ( because You cannot make null.showdialog for example ).

One also should keep in mind, that the Handle of the form may not yet be available in the ctor, where it surely will be already created when the event "onLoad" occurrs.

icbytes
  • 1,715
  • 16
  • 24
0

Constructor and formload is total different thing

  • Constructor is function which return class return type always where form load is event or from object.
  • Constructor call internally when you create instance of class where from load is call every time you fall into form_load signature.
  • constructor can overload for taking parameter where from load cannot be override.
Subhash Rao
  • 335
  • 2
  • 6