Use OnLoad or Load?

4 views
Skip to first unread message

Joe Kunk

unread,
Jan 20, 2005, 1:19:17 PM1/20/05
to GLU...@googlegroups.com
We had a spirited debate among the developers this week and I would
appreciate feedback on the topic. The issue regarding VB.NET WinForms
was whether it is better to use the "Load" event for form
initialization, or use the OnLoad event available in the "(Overrides)"
list. We want to set one or the other method as our standard for
writing events in Winforms and are trying to decide which one. The
impact seems to be in regards to inherited forms.

One group favors the OnLoad event since it can have code that runs
either before or after the parent's processing for that event, i.e.,
put in the "MyBase.OnLoad(e)" statement either before or after your
custom code. The down-side is that you MUST remember to manually
include that statement somewhere or the form's standard "Load" event
won't fire at all.

Another group considers the "Load" event better since it parallels the
form events available in VB6 and you don't have to remember to put in
the "MyBase.OnLoad(e): statement, but I believe it will always run
after the parent's Load event.

One obvious response would be to say to use whichever meets the current
app needs, but we want to standardize on one method to make working on
each others' code easier.

There seems to be more event choices in the "(Overrides)" list but I
haven't done a direct comparison yet.

We are leaning toward standarding on using the "(Overrides)" events in
all cases due to the extra flexibility, but we are wondering if there
are factors that we are not yet aware of. Are there any down-sides to
this that we are missing? If we have a child inherit from a form that
uses an OnLoad, will that cause any problems? Will the child still be
able to override it with it's "OnLoad" event?

I appreciate any comments and further clarification of how this works
and any impacts. Thanks !!!

Joe Kunk

ryan.doom

unread,
Jan 21, 2005, 11:33:05 AM1/21/05
to GLU...@googlegroups.com
Hey Joe, on works dime right now ;) but ill jump in and add a little
bit on the subject.
I would not recommend adding it to an 'event' if you are planning on
using this when inheriting. I am also not up to date on my VB.NET,
where i would think to put this would be in the 'constructor'... the
constructor is called when the class is created, and in forms creates
all your UI objects etc. in C# it would do that by calling
InitializeComponents.

That would be my instinctive to place to put such code (or call a
method that does what you need to setup) in the constructor for ease of
inheritance.

Hope this touched on enough to be of use.

Reply all
Reply to author
Forward
0 new messages