Color Property DefaultValue

T

timtos

I want to set a color property of a user control by default.
I am doing it like this:

....
DefaultValue(typeof(System.Drawing.Color), "Blue"),
....

The compiler likes it but my program ignores it!
I´ve also tried other things like:

DefaultValue(typeof(Color), "Blue"),
DefaultValue(typeof(Color), "Color.Blue"),
DefaultValue(typeof(System.Drawing.Color), "0, 0, 255"),
DefaultValue(typeof(System.Drawing.Color), "0; 0; 255"),

Searching the net I found a lot of solutions like the ones above.
But the problem is none of them are working for me.

Any ideas?
Thanks,
timtos.
 
J

Jay B. Harlow [MVP - Outlook]

Timtos,
The DefaultValue attribute tells the designer what the constructor of your
object considers the default value. You still need to set the default for
the backing field on the property to the default, I normally do this in the
constructor.

I normally use:
DefaultValue(typeof(System.Drawing.Color), "Blue"),

Hope this helps
Jay

In the constructor of your
 

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