Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / December 2004

Tip: Looking for answers? Try searching our database.

DesignMode help?

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
WXS - 07 Dec 2004 21:25 GMT
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
writing.  Currently the DesignMode flag is not set till the ISite is set
which unfortuantely happens after construction of whatever object, control or
component you are in, which means a signficant amount of code may run before
being able to determine design mode.  

So how do we stop code from running if we can't detect design mode.  What we
have tried to do in some cases is protected code with null checks and other
checks to avoid issues but that could make it harder to track real issues at
run time and is not always workable.

Is there a way we can determine design mode in the construction of the
object?  Without that we're pretty much stuck.

Thanks
Mike in Paradise - 07 Dec 2004 21:45 GMT
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

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.