Form Load Events

  • Thread starter Thread starter Charles A. Lackman
  • Start date Start date
C

Charles A. Lackman

Hello All,

I have a large application with multiple Windows Forms. I have code that
needs to be executed in the Load Event of every Form in the application and
was wondering if there was a way to add the code without having to go to
each form and copy and paste?

Is there a global location to override all the Load Events?

Thanks,

Chuck
 
Charles said:
Hello All,

I have a large application with multiple Windows Forms. I have code that
needs to be executed in the Load Event of every Form in the application and
was wondering if there was a way to add the code without having to go to
each form and copy and paste?

Is there a global location to override all the Load Events?

If it's possible to derive all Forms from your own base Form, you
can put the common code into the (overridable) OnLoad method of
the base Form.
 
If each form needs the exact same code, you are going to have some
repetition, but instead of putting the full-blown code in each Form_Load,
why not create the code in a separate class that gets instantiated when your
first form is created and then each Form_Load can simply have a single line
method call into that instance?

This way you'll reduce the amount of code repitition and if you ever need to
change the Form_Load code, you'll only have to do it in one place.

-Scott
 
Back
Top