470,596 Members | 1,222 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,596 developers. It's quick & easy.

if (this.DesignMode) return ; Not working

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
3 16719
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
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
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

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Asad Khan | last post: by
1 post views Thread by nntp | last post: by
3 posts views Thread by Bob Rivers | last post: by
7 posts views Thread by jammie_linux | last post: by
4 posts views Thread by Paul | last post: by
2 posts views Thread by graeme g | last post: by
12 posts views Thread by Sheldon | last post: by
1 post views Thread by Phil Latio | last post: by
2 posts views Thread by ft310 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.