if (this.DesignMode) return ; Not working

  • Thread starter Thread starter Sagaert Johan
  • Start date Start date
S

Sagaert Johan

Hi

I stumbled to this :

I have a form and in the contructor i put
if (this.DesignMode)
return;
other code here

The IDE designer throws an exception and points to a line in the 'other
code" block .

Any reason why ?
 
DesignMode is not usable in the constuctor; try putting this code (both
DesignMode and what you want to do) into a handler on the Load event.

Marc
 
Sagaert said:
Hi

I stumbled to this :

I have a form and in the contructor i put
if (this.DesignMode)
return;
other code here

The IDE designer throws an exception and points to a line in the 'other
code" block .

Any reason why ?

Hi,

Because you're in the constructor of your object, it stands to reason that
DesignMode will *not* have a value... since you're only _just_ constructing
your object, nothing will have set DesignMode.

There's another way to do it, but I cannot remember off the top of my head.
Something to do with a license manager IIRC.
 
I usually have a base class like this for forms and user controls.

public class BaseDesignModeUserControl : UserControl
{
private static readonly bool isDesignMode;

static BaseDesignModeUserControl()
{
isDesignMode =
(System.Diagnostics.Process.GetCurrentProcess().ProcessName.IndexOf("devenv")
!= -1);
}


protected bool IsDesignMode
{
[DebuggerStepThrough]
get
{
return isDesignMode;
}
}

}
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Back
Top