Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Prevent code from running only in visual studio designer

I have a custom control that I have written that does some location checking in the Load event of the control. This location checking moves the control to a specific location on the screen based on settings in its parent control. This code works as expected when I compile and run the application.

However, when using the Visual Studio designer, it causes my control to be painted outside of the viewable area and I cannot use the designer. Is there a flag or attribute I can set to stop that snippet of code from running ONLY when in the Visual Studio designer?

The only work around I have right now is to comment out the code, compile, launch designer, make my changes, then uncomment the code and re-compile.

like image 306
Michael Mankus Avatar asked Dec 09 '22 21:12

Michael Mankus


1 Answers

You could check the value of LicenseManager.UsageMode.

if (LicenseManager.UsageMode == LicenseUsageMode.Runtime)
{
    // Code here won't run in Visual Studio designer
}
like image 182
ken2k Avatar answered Jan 18 '23 23:01

ken2k