How to tell when a form is being designed?

Posted on 2007-10-17
Last Modified: 2010-04-15
I've got code in my form load.

When I switch to design view, the design crashes with an exception. It looks like it is running my Load code - if I comment this out, I can see a design time view of my form.

In delphi, a form had a ComponentState property - this indicated, amongst other things if the form was being designed (you could omit certain code from executing if this was the case). Is there a C# equivalent - i.e. how can I stop the form designer from running my Load code - or at least limit which code it is trying to execute.


Question by:steve-west
    LVL 21

    Accepted Solution

    Here is a solution for your problem

    Author Comment

    Job done.

    LVL 12

    Expert Comment

    DesignMode doesn't work in several cases - it depends on the parents all being set correctly. You'll find it's often 'wrong'...

    So I'd use LicenseManager.UsageMode instead, which always seems to work..

    Author Comment

    Thanks for the info, andrewjb.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
    Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
    Need more eyes on your posted question? Go ahead and follow the quick steps in this video to learn how to Request Attention to your question. *Log into your Experts Exchange account *Find the question you want to Request Attention for *Go to the e…
    Here's a very brief overview of the methods PRTG Network Monitor ( offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…

    761 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    13 Experts available now in Live!

    Get 1:1 Help Now