Use of the DesignMode property

bwells

Regular
Joined
Feb 25, 2003
Messages
84
In one of my Form derived classes, there is a line of code that causes the designer to show an error, but it is fine at run time. I thought I could use the "if( !this.DesignMode ) test to only run the line of code at run time, but this does not work and I still get the design time error. But if I say if ( this.DesignMode ), it evaulates to false both at design time and run time, so it looks like this property is always false, at design time and at run time.

There must be something special about using the DesignMode property in a Form that I am missing. Do you have any other suggestions as to how I should deal with code that seems to break my use of the designer? Its only by trial & error that I was able to narrow down to the line of code that breaks the designer, and I am still not sure what is the problem with the line of code that is causing the problem.

thanks
Bryan
 
i have a similar issue in the General section of these forums.
I was told that you can't use this property in Sub New()... although i haven't tested it yet i have a feeling that you are experiencing the problem i'm about to have when i get home from school today..
check out my post to get more info
 
bpayne111 is correct, that property does not work in the constructor. I explained why in his post in the General forum.
 
I am calling .designmode from a constructor.

So that is my mistake.

Its good to know this limitation.
 
When you consider that you can't change anything about a class before the constructor is run (think about it for a second, constructor always comes first) it makes sense.
 
I was accessing a static data member which (normally) gets instantiated when the main application is run. This data member was designed to manage serialization for the class in question. The data being accessed was the form position and location. So I can move this initialization to the onLoad event. It seems to me to make sense to expect a form to get its position and location at construction time, but in design mode of course, there is no serialization, so that is what caused me to look into the designmode property to prevent the class deserializing its data at design time. Normally, I would expect the class itself to be automatically deserialized, but Forms cannot be serialized, so that is why I separated the data from the form.

But I understand your point that most anything I might want to do in a constructor can be done at a later time.
 
Back
Top