Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- System.ComponentModel.DesignMode property
- System.ComponentModel.LicenseManager.UsageMode property
- private string ServiceString()
- {
- if (GetService(typeof(System.ComponentModel.Design.IDesignerHost)) != null)
- return "Present";
- else
- return "Not present";
- }
- public bool IsDesignerHosted
- {
- get
- {
- Control ctrl = this;
- while(ctrl != null)
- {
- if((ctrl.Site != null) && ctrl.Site.DesignMode)
- return true;
- ctrl = ctrl.Parent;
- }
- return false;
- }
- }
- public static bool IsInDesignMode()
- {
- return System.Reflection.Assembly.GetExecutingAssembly()
- .Location.Contains("VisualStudio"))
- }
- if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)
- {
- bla bla bla...
- }
- /// <summary>
- /// The DesignMode property does not correctly tell you if
- /// you are in design mode. IsDesignerHosted is a corrected
- /// version of that property.
- /// (see https://connect.microsoft.com/VisualStudio/feedback/details/553305
- /// and http://decav.com/blogs/andre/archive/2007/04/18/1078.aspx )
- /// </summary>
- public bool IsDesignerHosted
- {
- get
- {
- Control ctrl = this;
- while (ctrl != null)
- {
- if ((ctrl.Site != null) && ctrl.Site.DesignMode)
- return true;
- ctrl = ctrl.Parent;
- }
- return false;
- }
- }
- public bool RealDesignMode()
- {
- if (Parent is MyBaseUserControl)
- {
- return (DesignMode ? true : (MyBaseUserControl) Parent.RealDesignMode;
- }
- return DesignMode;
- }
- static bool IsDesignMode(Control control)
- {
- PropertyInfo designModeProperty = typeof(Component).
- GetProperty("DesignMode", BindingFlags.Instance | BindingFlags.NonPublic);
- while (designModeProperty != null && control != null)
- {
- if((bool)designModeProperty.GetValue(control, null))
- {
- return true;
- }
- control = control.Parent;
- }
- return false;
- }
- public MyUserControl()
- {
- InitializeComponent();
- m_IsInDesignMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);
- }
- private bool m_IsInDesignMode = true;
- public bool IsInDesignMode { get { return m_IsInDesignMode; } }
- /// <summary>
- /// Gets a value indicating whether this instance is in design mode.
- /// </summary>
- /// <value>
- /// <c>true</c> if this instance is in design mode; otherwise, <c>false</c>.
- /// </value>
- protected bool IsDesignMode
- {
- get { return DesignMode || LicenseManager.UsageMode == LicenseUsageMode.Designtime; }
- }
Add Comment
Please, Sign In to add comment