Well, my thinking on this problem was along these lines...
You want to set the property (AutoSize) of the base class to a different
value than its default. The base class AutoSize property has a
DefaultValueAttribute with a value of "false". So you set a different value
("true") into the base AutoSize property in your derived controls
constructor. Now, that property should be serialized into the
InitializeComponent method ("this.labelBase1.AutoSize = true;") since it
does not match the default value ("false"). All is well as this point. Now,
when you change the value to "false", there is no need to serialize the
value as it matches the bases default AutoSize value. The appropriate line
in the InitializeComponent method will be removed. For the duration that you
have the Form open in the designer, the control instance is storing the
value of "false". When you run the code, or when you close the Form and
reopen it in the designer, the bases AutoSize is again set in the
constructor to "true" and the value is not set to "false" in the
InitializeComponent method as you would think due to what was mentioned
previously - the line "this.labelBase1.AutoSize = false;" has been removed
since the control believes it is not necessary.
So the code that I posted will override the AutoSize property, still using
the bases implementation through the getter and setter, but it changes the
default value, through the DefaultValueAttribute, to line up with the
desired default. Not only would this give a better design experience, but
when the value is changed to "false" it will be serialized.
Are you sure that you have overriden the AutoSize in your class and
specified the DefaultValueAttribute?
--
Tim Wilson
..Net Compact Framework MVP
"Greg" <Gr**@discussions.microsoft.com> wrote in message
news:A8**********************************@microsof t.com...
Sorry, no luck with doing this. It seems odd to me that I can set a
property in the property sheet of a form, and that it reverts on saving the form.
It seems like such a simple thing to me to be able to override a base class
property.
"Tim Wilson" wrote:
I would say override the AutoSize property and specify the
DefaultValueAttribute as "true".
[DefaultValue(true)]
public override bool AutoSize
{
get
{
return base.AutoSize;
}
set
{
base.AutoSize = value;
}
}
public LabelBase()
{
this.AutoSize = true;
}
--
Tim Wilson
..Net Compact Framework MVP
"Greg" <Gr**@discussions.microsoft.com> wrote in message
news:E4**********************************@microsof t.com... I have a base class for a label. I want to set a property at the base
class level, say AutoSize = true. Then at the form level I want to be able
to overide the base class setting so that I can turn it off when needed.
What is happening is that at the form level, I can set the autosize to
false, but then when I recompile, the autosize is set back to true.
This is what the base class looks like:
public class LabelBase : Label
public LabelBase()
{
this.AutoSize = true ;
}
Is there some other way that I should be doing this so that I can
override it at the form level.
--
Greg Gum