DesignMode not working

G

graeme g

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
 
B

Bruce Wood

graeme said:
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 ...
}
}
}
 
G

graeme g

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...



:)
 

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

Top