bwells Posted March 17, 2003 Posted March 17, 2003 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 Quote
bpayne111 Posted March 17, 2003 Posted March 17, 2003 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 Quote i'm not lazy i'm just resting before i get tired.
*Gurus* divil Posted March 17, 2003 *Gurus* Posted March 17, 2003 bpayne111 is correct, that property does not work in the constructor. I explained why in his post in the General forum. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Heiko Posted March 17, 2003 Posted March 17, 2003 I am using "if not me.designmode" in a property setter and it works fine. Where/When exactly is your "designmode" checker called? Quote .nerd
bwells Posted March 17, 2003 Author Posted March 17, 2003 I am calling .designmode from a constructor. So that is my mistake. Its good to know this limitation. Quote
*Gurus* divil Posted March 17, 2003 *Gurus* Posted March 17, 2003 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. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
bwells Posted March 18, 2003 Author Posted March 18, 2003 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. Quote
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.