base form's load event gets fired when form designer open.

F

feng

We have a windows form project that has multiple child
forms inherit from one base form. In our base form's form
load event handler, we have some common logic in there.
These common logic is needed by all the child forms when
they load up. So when a child form gets called, the base's
form load event handler gets called first, so is the
common logic, then the child's load event handler gets
executed.

So far, everything works fine, except one: the base form's
load event handler gets executed not only at run time, but
also at the design time, when the child form is opened in
the form designer! This is so problematic, bucause we get
errors each time we open the designer. That's because a
lots of things that our common logic needs to run are not
available at the design time (of course!).

Can someone tell me if this is expected behavior? Is there
a way we can skip this execution at design time? Or any
other suggestions?

Thanks
 
F

Fergus Cooney

Hi Feng,

You can test whether you are in running within the Designer using the
DesignMode property.

Let me know if you have any problems using this. There have been issues
with UserControls. I don't know if it will be the same with inherited Forms.

Regards,
Fergus
 
A

Armin Zingler

feng said:
We have a windows form project that has multiple child
forms inherit from one base form. In our base form's form
load event handler, we have some common logic in there.
These common logic is needed by all the child forms when
they load up. So when a child form gets called, the base's
form load event handler gets called first, so is the
common logic, then the child's load event handler gets
executed.

So far, everything works fine, except one: the base form's
load event handler gets executed not only at run time, but
also at the design time, when the child form is opened in
the form designer! This is so problematic, bucause we get
errors each time we open the designer. That's because a
lots of things that our common logic needs to run are not
available at the design time (of course!).

Can someone tell me if this is expected behavior? Is there
a way we can skip this execution at design time? Or any
other suggestions?


If Not Me.Designmode Then
'code
End If
 
H

Herfried K. Wagner [MVP]

* "feng said:
So far, everything works fine, except one: the base form's
load event handler gets executed not only at run time, but
also at the design time, when the child form is opened in
the form designer! This is so problematic, bucause we get
errors each time we open the designer. That's because a
lots of things that our common logic needs to run are not
available at the design time (of course!).

Can someone tell me if this is expected behavior? Is there

Yes, this behavior is by design. You can check 'Me.DesignMode' in the
base form to execute the code only if the form is shown in design mode.
 

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