Q: How to tell if a component function is executed at design time or runtime?

  • Thread starter Thread starter Martin Arvidsson
  • Start date Start date
M

Martin Arvidsson

Hi!

I have developed a component that creates a lookup for selecting values.
At designtime i want to display the windows as well but with certain
criterias.
is there a property or something to look at that tells mee if its designtime
or runtime?

Regards
Martin
 
Hi Martin,

Every Type derived from System.ComponentModel.Component (which includes all
Controls and the Form class itself) has a Site property. Visual Studio sets
the Site when the Component is being hosted by a designer. In that case the
Site.DesignMode property will be true. At runtime, check if Site is null or
Site.DesignMode is false:

if (Site == null || !Site.DesignMode)
{
// not in design mode
}

You can't perform this check in the constructor, however, because VS hasn't
set the Site property yet. (The Site property can't be set by VS until after
the Component is constructed, obviously)
 
Hi Martin,
Every Type derived from System.ComponentModel.Component ...

It should really say, "Every class that derives from
System.ComponentModel.Component ..."

Just wanted to clear that up so you didn't think I was referring to the
System.Type class :)
 

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

Back
Top