Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

Prevent code executing at Design Time in Visual Studio for Winforms Apps

0.00/5 (No votes)
18 Feb 2010 1  
If you are designing in a WinForms component, which is anything that derives from Control at some point (Forms, UserControls, panels, etc), then you can use the following code:if (this.Site.DesignMode) //Do stuff[edit]The above will throw an exception if Site is not set (in...
If you are designing in a WinForms component, which is anything that derives from Control at some point (Forms, UserControls, panels, etc), then you can use the following code:

<br />
if (this.Site.DesignMode)<br />
   //Do stuff<br />


[edit]
The above will throw an exception if Site is not set (in most cases it is, ie the control is in a container control). However:

C
if (this.DesignMode)
   //Do stuff

Will return false if there is no container. This is an alternative (and much neater) method, but may give incorrect results in certain (rare) circumstances.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here