Is there a way to detect if the application is in Design Time mode?

0
0

Hi,

I have created a Wisej User Control and added to a form.  However I found out if you have a bug like a null exception in the Load Event of the user control Visual Studio crashes every time you open a form with the offending user control.  This is because the Load Event is executed when it is being rendered in design time.

I have corrected the bugs and all is good, however sometimes I like to load a DataSource in my User Control Load Event and if the data source is not available it can also cause similar problems.

So I was wondering is there and if statement I can call to detect whether I am in Design Time to exclude certain operations?

I found these statements for WinForms that does this, however they do not appear to work for my Wisej Project.

public static bool InDesignMode
{
get => (LicenseManager.UsageMode == LicenseUsageMode.Designtime) ||
(System.Diagnostics.Process.GetCurrentProcess().ProcessName == “devenv”) ||
(Application.ExecutablePath.IndexOf(“devenv.exe”, StringComparison.OrdinalIgnoreCase) > -1);
}

So in my Form Load Event I would call this function to bypass code blocks like this:

if (!InDesignMode)
{
// load datasource
}

Maybe I am doing something else wrong,

Thanks,

Devin

  • You must to post comments
0
0

Hi David,

We do have the DesignMode property to achieve what you want.

You can use it to determine whether your UC is in design mode or not!

Best,
Alaa

  • You must to post comments
Showing 1 result
Your Answer

Please first to submit.