tony wrote:
Hello!
I have a demo program that have this event handler Form1_Load below.
I just wonder is it any difference if the call to this Form1_Load is removed
and the call to InitGrid() is done
in the constructor instead.
So what is the point having this method Form1_Load if the same can be done
in the constructor?
private void Form1_Load(object sender, System.EventArgs e)
{
InitGrid();
}
//Tony
I believe it will be just fine for you to put the call to InitGrid in
the constructor, as long as you put the call below the
InitializeComponent() method. This ensures that all the components on
the form are instantiated before any attempt at accessing them from your
method. As far as why there is Form_load event, the reason is you can
construct the form ahead of time but not have the form "load" per say
and eventually you can call Show() or ShowDialog() and then the event
will be called. This separation gives you the ability to separate
initialization code in the constructor from code that will update the UI
before it is shown in the form_load event.
Hope this helps.
Justin