DesignMode property does not always return the correct value, specially for nested controls or for child controls instantiated in their parent control’s constructors. One workaround is to check for
LicenseManager.UsageMode and see if it’s equal to
LicenseUsageMode.Runtime, but even that won’t work all the time. It will always return
Runtime from event handlers and worker threads, so a more guaranteed approach is to see if the current process-name is devenv. Of course that’s a slightly heavier call so we should still check for
LicenseManager.UsageMode first, and only check the process-name if we have to.
bool isDesignMode = LicenseManager.UsageMode == LicenseUsageMode.Designtime || Process.GetCurrentProcess().ProcessName.ToLowerInvariant().Contains("devenv");