Detecting design mode from a Control's constructor

You can use the LicenceUsageMode enumeration in the System.ComponentModel namespace:

bool designMode = (LicenseManager.UsageMode == LicenseUsageMode.Designtime);

Are you looking for something like this:

public static bool IsInDesignMode()
{
    if (Application.ExecutablePath.IndexOf("devenv.exe", StringComparison.OrdinalIgnoreCase) > -1)
    {
        return true;
    }
    return false;
}

You can also do it by checking process name:

if (System.Diagnostics.Process.GetCurrentProcess().ProcessName == "devenv")
   return true;

Component ... as far as I know does not have the DesignMode property. This property is provided by Control. But the problem is when CustomControl is located in a Form in the designer, this CustomControl is running in runtime mode.

I have experienced that the DesignMode property works correct only in Form.

Tags:

C#

Winforms