Reputation: 135
In Visual Studio C# Windows form application, what is the deferent between class constructor and form load?
Upvotes: 0
Views: 2941
Reputation: 335
Constructor and formload is total different thing
Upvotes: 0
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
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
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
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