471,317 Members | 2,606 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,317 software developers and data experts.

Set DefaultValue property attribute to non constant value.

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.
Feb 3 '06 #1
2 7722
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]
- mv*@spam.guard.caspershouse.com

"Steve" <st**********@lineone.net> wrote in message
news:us****************@TK2MSFTNGP15.phx.gbl...
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.

Feb 3 '06 #2
It does.

Thanks.
Steve
"Nicholas Paldino [.NET/C# MVP]" <mv*@spam.guard.caspershouse.com> wrote in
message news:OK**************@TK2MSFTNGP09.phx.gbl...
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]
- mv*@spam.guard.caspershouse.com

"Steve" <st**********@lineone.net> wrote in message
news:us****************@TK2MSFTNGP15.phx.gbl...
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.


Feb 4 '06 #3

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

2 posts views Thread by timtos | last post: by
5 posts views Thread by schneider | last post: by
6 posts views Thread by Meelis Lilbok | last post: by
6 posts views Thread by Peter Hartlén | last post: by
5 posts views Thread by =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post: by
reply views Thread by rosydwin | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.