Form Load Events

  • Thread starter Charles A. Lackman
  • 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
 
A

Armin Zingler

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.
 
S

Scott M.

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top