How to tell if .NET code is being run by Visual Studio designer
To find out if you're in "design mode":
- Windows Forms components (and controls) have a DesignMode property.
- Windows Presentation Foundation controls should use the IsInDesignMode attached property.
if (System.ComponentModel.LicenseManager.UsageMode == System.ComponentModel.LicenseUsageMode.Designtime)
{
// Design time logic
}