Geeks With Blogs

Nat Luengnaruemitchai Geek Blog

Well, a bunch of people have raised an issue with DesignMode property doesn't work quite well. Fabrice already suggested some workarounds which are

1. this.GetService(typeof(IDesignerHost)) !=null

2. System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime

3. System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv"

Today, I just experienced a problem where I used method 3 to detect whether a control is in DesignMode or not. This test will fail when executing under Citrix Metaframe under limited privilege since the user will not have enough permission to obtain process information. It will throw an exception and make it unable to figure out whether it is in DesignMode or not. Plus the fact that the control can be hosted in other IDE such as Borland Delphi, MonoDevelop or SharpDevelop which may yield different result. So I would like to suggest removing number 3 from the list.


Posted on Wednesday, April 27, 2005 10:04 PM Programming | Back to top

Comments on this post: DesignMode Problem

# re: DesignMode Problem
Requesting Gravatar...
yes Design time need parent
so use ISupportInitialize
code now - think later

public class foobar : UserControl, ISupportInitialize{
#region ISupportInitialize Members
private bool ISupportInitialize_bInit=false;
public void BeginInit() {

public void EndInit() {
if (this.DesignMode){
} else {

Left by dr. gna on May 19, 2005 11:56 AM

# re: DesignMode Problem
Requesting Gravatar...
Thanks for isolating the problem!
Ok, here's what I found:
#1 Fails when opening a project!
#2 Fails when closing a project!

And the solution is...
private bool _DesignMode
return (this.GetService(typeof(IDesignerHost)) != null) || (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime);
Left by Jacob Sobaszkiewicz on Jun 24, 2008 6:46 PM

# re: DesignMode Problem
Requesting Gravatar...
Fair do Jacob for finding the code that solves everyone's problem!
Left by wikileaks internetcafe on Dec 05, 2010 5:47 AM

Your comment:
 (will show your gravatar)

Copyright © Nat Luengnaruemitchai | Powered by: