HOW TO: Set a DefaultValueAttribute to system color?

  • Thread starter Thread starter Zoury
  • Start date Start date
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!
 
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.
 
Back
Top