Set DefaultValue property attribute to non constant value.

  • Thread starter Thread starter Steve
  • Start date Start date
S

Steve

Hi, I would like to set the default value of a property on my control by:
[System.ComponentModel.DefaultValue( typeof(Color),
SystemColors.WindowText.ToString() )]

but can't because SystemColors.WindowText is not a constant. Microsoft
controls do it, can I - is there a work round?

I can cheat by...
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would this
have any problems with internationalisation - would the control work on a
german,french,etc.. machine.

Thanks in advance.
Steve.
 
Steve,

No, you can not do it. Microsoft controls don't do it any differently
than you do. They do:

[DefaultValue(typeof(Color), "WindowText")]

Just like you would do.

And no, this would not have a problem in other languages. The color
converter uses the properties as they are exposed off the Color and
SystemColor classes, which are in english.

Hope this helps.
 
It does.

Thanks.
Steve


Nicholas Paldino said:
Steve,

No, you can not do it. Microsoft controls don't do it any differently
than you do. They do:

[DefaultValue(typeof(Color), "WindowText")]

Just like you would do.

And no, this would not have a problem in other languages. The color
converter uses the properties as they are exposed off the Color and
SystemColor classes, which are in english.

Hope this helps.


--
- Nicholas Paldino [.NET/C# MVP]
- (e-mail address removed)

Steve said:
Hi, I would like to set the default value of a property on my control
by:
[System.ComponentModel.DefaultValue( typeof(Color),
SystemColors.WindowText.ToString() )]

but can't because SystemColors.WindowText is not a constant. Microsoft
controls do it, can I - is there a work round?

I can cheat by...
[System.ComponentModel.DefaultValue(typeof(Color), "Black")]

but its not quite what I want. Plus: if I use the cheat("Black") would
this have any problems with internationalisation - would the control work
on a german,french,etc.. machine.

Thanks in advance.
Steve.
 
Back
Top