HOW TO: Set a DefaultValueAttribute to system color?

Z

Zoury

Hey guys! :O)

i'd like to know how would one set a default color property to a system
color ?

as you might guess, this code doesn't work ...
//***
[DefaultValue((object)Color.FromKnownColor(KnownColor.Window))]
public void MyProp
{
//....
}
//***

thanks in advance!
 
N

Nicholas Paldino [.NET/C# MVP]

Zoury,

You will want to declare your attribute like this:

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

This above line will have the designer look for the Color type. When it
gets it, it will look for the TypeConverter attribute on the type to
indicate what TypeConverter to use. Once it gets that, it will pass the
string "ControlText" to the ConvertFromString method to get the color to
actually use.

Hope this helps.
 

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