Set DefaultValue property attribute to non constant value.

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.
 
N

Nicholas Paldino [.NET/C# MVP]

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.
 
S

Steve

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top