363,924 Members | 2598 Browsing Online
Community for Developers & IT Professionals
Bytes IT Community

if (this.DesignMode) return ; Not working

Sagaert Johan
P: n/a
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 ?
















Oct 20 '06 #1
Share this Question
Share on Google+
3 Replies


Marc Gravell
P: n/a
Marc Gravell
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

Oct 20 '06 #2

Tom Spink
P: n/a
Tom Spink
Sagaert Johan wrote:
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.

--
Hope this helps,
Tom Spink

Google first, ask later.
Oct 20 '06 #3

Bill Rodenbaugh
P: n/a
Bill Rodenbaugh
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().Pr ocessName.IndexOf("devenv")
!= -1);
}


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

}


Sagaert Johan wrote:
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 ?
Oct 21 '06 #4

Post your reply

Help answer this question



Didn't find the answer to your C# / C Sharp question?

You can also browse similar questions: C# / C Sharp c# designmode