469,902 Members | 2,007 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

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

DesignMode not working

ii

i've been developing some usercontrols... and sudden the property designmode
no longer works.. if i test it value at designtime it always comes back
false...

i've made a work around

if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
b_designMode = true;
else
b_designMode = false;

b_designMode to a private bool in the class

anyone know why it stopped working?

thanks

g
Aug 16 '06 #1
2 4216

graeme g wrote:
ii

i've been developing some usercontrols... and sudden the property designmode
no longer works.. if i test it value at designtime it always comes back
false...

i've made a work around

if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
b_designMode = true;
else
b_designMode = false;

b_designMode to a private bool in the class

anyone know why it stopped working?
I'm guessing that it's because you're testing it in your control's
constructor. The DesignMode property always returns false until the
control's window handle is set, which happens some time before the Load
event.

You should put all long-running code in the control's OnLoad method.
Just initialize everything to null in the constructor. DesignMode will
give a correct value in the OnLoad method:

public MyControl : UserControl
{
public MyControl()
{ ... set everything to null ... }

protected override void OnLoad(EventArgs e)
{
if (!this.DesignMode)
{
... do user control set-up here ...
}
}
}

Aug 16 '06 #2
Thanks for your help

I read that it doesn't work in the constructor... and I thought but it's not
in the constructor... but it turned out that I was calling a function in the
constructor which caused the problem...

It been one of those weeks...

:-)

"Bruce Wood" <br*******@canada.comwrote in message
news:11**********************@p79g2000cwp.googlegr oups.com...
>
graeme g wrote:
>ii

i've been developing some usercontrols... and sudden the property
designmode
no longer works.. if i test it value at designtime it always comes back
false...

i've made a work around

if (LicenseManager.UsageMode == LicenseUsageMode.Designtime)
b_designMode = true;
else
b_designMode = false;

b_designMode to a private bool in the class

anyone know why it stopped working?

I'm guessing that it's because you're testing it in your control's
constructor. The DesignMode property always returns false until the
control's window handle is set, which happens some time before the Load
event.

You should put all long-running code in the control's OnLoad method.
Just initialize everything to null in the constructor. DesignMode will
give a correct value in the OnLoad method:

public MyControl : UserControl
{
public MyControl()
{ ... set everything to null ... }

protected override void OnLoad(EventArgs e)
{
if (!this.DesignMode)
{
... do user control set-up here ...
}
}
}

Aug 16 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by Lecture Snoddddgrass | last post: by
3 posts views Thread by Bob Rivers | last post: by
5 posts views Thread by Larry | last post: by
29 posts views Thread by Charles Law | last post: by
1 post views Thread by Paul W | last post: by
1 post views Thread by Larry | last post: by
3 posts views Thread by Sagaert Johan | last post: by
1 post views Thread by Waqarahmed | last post: by
reply views Thread by Salome Sato | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.