visual-studiogui-designer

How to tell if .NET code is being run by Visual Studio designer


I am getting some errors thrown in my code when I open a Windows Forms form in Visual Studio's designer. I would like to branch in my code and perform a different initialization if the form is being opened by designer than if it is being run for real.

How can I determine at run-time if the code is being executed as part of designer opening the form?


Solution

  • To find out if you're in "design mode":