Bizarre behavior in design mode when inheriting from a form with a timer.

  • Thread starter Thread starter Michael.Suarez
  • Start date Start date
M

Michael.Suarez

this is so bizarre. Try it for yourself.

In VS 2005:
Create a windows control library with 1 form. The only control on the
form is 1 enabled timer whose tick event has MessageBox.Show("hello");

Build this library, and reference it from another windows form
application. Now create an inherited form, inheriting from the form you
just created.

What you will witness is this:

While you have the Windows App project open, in design mode, somehow
the timer will be ticking and it's tick event will get raised. And you
will actually see the message box pop up while you are in design mode!!

Can anyone explain why this happens?
Should this be expected? or is this a major bug?
 
It should be expected.

--
HTH,

Kevin Spencer
Microsoft MVP
..Net Developer
A brute awe as you,
a Metallic hag entity, eat us.
 
Is there any way to prevent it?
The timer I created is meant to be running when the application is
running, not when its in design mode.
 
Is there any way to prevent it?
The timer I created is meant to be running when the application is
running, not when its in design mode.

if( !DesignMode )
{
// start timer
}
 
Thanks!

What threw me off is that I wasn't expecting the code from the base
form to be executed while in design mode. I assumed code was only meant
to be executed at run time. But being as you can control what gets
executed at design time by using this.DesignMode, it's a cool feature.

One note about using this.DesignMode in is, at least what i was
experiencing, that DesignMode will always be false when you are
checking it from the constructor. Therefore, I had to check for
DesignMode in the Load event of the form.
 
Back
Top