Thanks so much.  The ShouldSerialize is definitely the trick.  I'm about to
try it out, but in the documentation under the ShouldSerialize and Reset
methods, the following as-yet-overlooked-by-me nugget appears

====================
ShouldSerialize and Reset are optional methods that you can provide for a
property, if the property does not a have simple default value. If the
property has a simple default value, you should apply the
DefaultValueAttribute and supply the default value to the attribute class
constructor instead. Either of these mechanisms enables the following
features in the designer.

and

Note:  Either apply the DefaultValueAttribute or provide ResetPropertyName
and ShouldSerializePropertyName methods. Do not use both.
====================

The example of a complex default value they use is actually a Font, so the
example is perfect.

Thanks again.

Jeff



On Thu, 16 May 2002 13:34:33 -0500, Jacob Grass
<[EMAIL PROTECTED]> wrote:

>Heh.. . .Font is a different ball of wax.  You don't want to use
DefaultValue on Font because you can only specify Static values.  You
should create a ShouldSerializeFont method on the class that defines the
property.  So, something like this:
>
><code snippet = C#>
>
>private bool ShouldSerializeFont()
>{
>        return !Font.Equals(new Font("Comic Sans MS", 2, FontStyle.Bold);
>}
>
></code snippet>
>
>Jacob A. Grass
>
>
>
>> -----Original Message-----
>> From: Jeff
>> Subject: Re: [DOTNET] DefaultValue() Attribute Question
>>
>>
>> The continuing saga:
>>
>> Color worked just fine as noted in earlier replies.
>>
>> DefaultValue(typeof(Color), "Control")
>>
>> Font is another story.
>>
>> I can't see why the following would fail for a custom font property:
>>
>> DefaultValue(typeof(Font), "Microsoft Sans Serif, 8.25pt")
>>

You can read messages from the DOTNET archive, unsubscribe from DOTNET, or
subscribe to other DevelopMentor lists at http://discuss.develop.com.

Reply via email to