Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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?

like image 488
Zvi Avatar asked Sep 16 '08 15:09

Zvi


People also ask

How do I see the Form design in Visual Studio?

From the Solution Explorer window select your form, right-click, click on View Designer. Voila! The form should display.

What is Visual Studio .NET how it fills in the .NET framework?

Visual Studio . NET is an application development tool for writing an application; the . NET Framework provides the infrastructure required to run those applications.

What is Visual Studio designer?

The Visual Studio Report Designer is a tool fully integrated into the famous IDE with WYSIWYG design surface, New Item support, Properties Grid integration, and three dedicated tool windows. This makes it a fully featured tool for creating and editing compiled (CS or VB) report definitions.


1 Answers

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.
like image 83
Roger Lipscombe Avatar answered Sep 21 '22 00:09

Roger Lipscombe