Try this...
private bool InDesignMode()
{
if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
{
return true;
}
return false;
}
> It seems to me there is no reliable way to detect design mode early enough to
> prevent, running code a significant amount of code in classes developers are
[quoted text clipped - 12 lines]
>
> Thanks
WXS - 08 Dec 2004 03:15 GMT
I tried this on a Form and I'm not sure the form's code ever get's called.
For a user control or a component this code works great and is the best
suggestion I've seen to date!
Thanks for that! Any ideas about the form thing?
Dave
> Try this...
> private bool InDesignMode()
[quoted text clipped - 22 lines]
> >
> > Thanks
WXS - 08 Dec 2004 15:01 GMT
It seems form code doesn't run at all from what I can tell at design time. I
put a message box in the constructor and it doesn't get called, tried
breakpoints there and that doesn't get called either.
I think Ideally Microsoft should have included a property that could have
been read from each class at construction time to avoid having to get license
managers and stuff. Maybe require a specific constructor for design mode for
example would have been fine.
Again your answer is the best I've seen barring Microsoft implementing the
above. \
The other responses I had seen were something along the lines of:
1. Dude don't run your code there, do it later
2. Do whatever you need to do when Site is set (not appropriate for runtime
though)
3. Check to see if your process is "devenv.exe" then you know your in
designer (yuck!)
4. Why are you using the designer?
(Ok, no one suggested the last one... but I was starting to wonder myself
when trying to find a suitable way to handle this.)
Thanks,
Dave
> Try this...
> private bool InDesignMode()
[quoted text clipped - 22 lines]
> >
> > Thanks
WXS - 08 Dec 2004 15:23 GMT
I tested this last night and it did work in the constructor with components
and controls in a test app. Just tried in our real controls here at work and
the usage mode is coming back at runtime even in the design mode at some
points.
We discovered that you can't use that code all of the time. It works great
in the constructor of the control or component, but if you try it later or in
other code it is not guaranteed to return the right value. So what we are
doing is we'll set our own design mode flag in the constructor based on this
flag.
Thanks,
Dave
> Try this...
> private bool InDesignMode()
[quoted text clipped - 22 lines]
> >
> > Thanks