Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Problem setting defaults for some new 2.0 properties
Message
From
18/01/2007 18:55:06
 
 
To
All
General information
Forum:
ASP.NET
Category:
Class design
Title:
Problem setting defaults for some new 2.0 properties
Miscellaneous
Thread ID:
01186832
Message ID:
01186832
Views:
76
OK, so, what is the deal with properties that cannot be set to a default in a "base" class?

For example, I have a base Button class, MyButton. When I drop MyButton on a form, it sets the UseVisualStyleBackColor to true. Well, since this is a new property with 2.0, the designer seems to want to stick a line of code in there setting it to true. I've been going through all my base classes and setting defaults and I want it to default to false ... Can't do it with this Property (same with a few others too).

I did all the usual right things ... set it to false in the constructor of MyButton and set a property with [DefaultValue(false)] ... the designer still sets it to true. So I tried a few other tricks ... the only things that worked were specifically setting it to false, either by returning false in the get, or setting the base.UseVisualStyleBackColor = false in the set. Not very good, because then it couldn't be set at all in the PropertySheet (but maybe that doesn't matter ... no one would probably be overriding only a few instances of a class).

Maybe I should just let it default to true? Any downsides to that? I'm just not sure we want to enable visual styles in our app to begin with. Does anyone have a solution or comments?

~~Bonnie
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Reply
Map
View

Click here to load this message in the networking platform