Nat Luengnaruemitchai

Geek Blog

  Home  |   Contact  |   Syndication    |   Login
  99 Posts | 0 Stories | 209 Comments | 236 Trackbacks

News

Archives

Post Categories

Blogroll

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

Feedback

# re: DesignMode Problem 5/19/2005 11:56 AM dr. gna
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() {
ISupportInitialize_bInit=true;
}

public void EndInit() {
ISupportInitialize_bInit=false;
if (this.DesignMode){
foo();
} else {
bar();
}
}

#endregion
}

# re: DesignMode Problem 6/24/2008 6:46 PM Jacob Sobaszkiewicz
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...
[CODE]
private bool _DesignMode
{
get
{
return (this.GetService(typeof(IDesignerHost)) != null) || (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime);
}
}
[/CODE]

Post A Comment
Title:
Name:
Email:
Website:
Comment:
Verification: