Design Mode Detection


Ultimate Contributor
Jun 10, 2003
The DesignMode property of the Control class is meant to be testable to see if the control is in design mode, allowing the programmer to produce different behavior at design time than at runtime. Unfortunately, the behavior of this property is particularly unreliable.

It certainly has frustrated me at times and I'm sure that it has frustrated others, so I did a quick google search and found a few work-arounds on a blog and another blog.

  • Test the value of GetService(typeof(IDesignerHost)) for null within a component. A null value indicates that the component is not hosted in a designer. This method did not work for me consistently.
  • Check System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime. A true value indicates design mode. I haven't tried this method.
  • Check that the process hosting the component is devenv. This is a less solid option because it won't work properly in certain circumstances, for example within VS add-ins or #Develop.
  • Add a public static field to a class (ideally the Program class) named DesignMode that is initialized to true. In your application's Main() set the field's value to false. Because your application's Main method is not run within the designer, DesignMode will return true in the designer and false outside the IDE. This method is my preferred method, but isn't available with an VB program that doesn't have a Main() method.
Last edited:
Top Bottom