"tony" <jo*****************@telia.comwrote in message
news:uZ**************@TK2MSFTNGP03.phx.gbl...
Hello!
When exactly is it important or advisable to use this form load event
handler compare to using the C-tor.
For example here I create an event handler called dataBoundGridForm that
is
called when the form is loaded.
this.Load += new System.EventHandler(this.dataBoundGridForm_Load);
Events are for one object to revieve notifications from another, they are
not really for an object to revieve notifications from itself. If you use
form.Load you should use the override OnLoad.
I mean if I compare form load with the C-tor I think that it's enough to
put
the code into the C-tor instead
of using the event handler for the form load.
From my understanding the actual window itself is not created until after
the form's constructor has exited. So anything you do in the constructor is
being stored in the Form class and is being passed to the actual window
later. For example if you set the caption of the form it will be stored in
the form and later set using SetWindowText (or something similar) after the
window is created. This is probably no big deal but I tend to do these
things in OnLoad now just because it makes more sense to do it when the
window actually exists.
On the other hand some things cause the window handle to be destroyed and
recreated if done in Onload. I can't remember exactly what but say hiding
the control box requires the window to be recreated. If this is done in
Onload then the entire form will be destroyed and recreated. If you set
several similar properties then it could happen several times.
So when can I skip form load and put the code into C-tor and
when is it important to use form load and put some code here.
If the form load is to be used what kind of functionallity should be put
here instead of using the C-tor.
I'm pretty sure API functions that require the window handle won't work
there but besides that I think just about everything can go there.
Michael