Da Xiong
Da Xiong

Reputation: 135

Defferent between constructor and form load?

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

Upvotes: 0

Views: 2941

Answers (5)

Subhash Rao
Subhash Rao

Reputation: 335

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.

Upvotes: 0

icbytes
icbytes

Reputation: 1851

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.

Upvotes: 0

Sriram Sakthivel
Sriram Sakthivel

Reputation: 73442

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.

Upvotes: 0

C0L.PAN1C
C0L.PAN1C

Reputation: 12243


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.

Upvotes: 0

Murdock
Murdock

Reputation: 4662

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

Upvotes: 3

Related Questions