Drawing.Color Problem

S

Shawn B.

Greetings,

In creating a server control I added a property of type
System.Drawing.Color.

When the control is rendered, it generates a style that contains a style
called "backgroundColor" that will hold the value of
[Property].ToKnownColor.

It works well, except in some cases (if you set a system-defined color) such
as the "Info" color. When it renders, it simply renders "Info" but in the
style, that's not a known color. The MS controls render it as
"InfoBackground" but I can't see where I get that name from. It appears
that I have to know all these variations in the system-defined colors and
replace them with the proper name. Is there an easier built-in way?


Thanks,
Shawn
 
S

saucer

try to use System.Drawing.ColorTranslator.ToHtml to convert the color for
you or you can always do

Color c = SystemColors.Info;
string s = ColorTranslator.ToHtml(c);

s = String.Format("#{0:x}{1:x}{2:x}", c.R, c.G, c.B);
 
S

Shawn B.

Hmm... that works. Thanks.

Thanks,
Shawn


saucer said:
try to use System.Drawing.ColorTranslator.ToHtml to convert the color for
you or you can always do

Color c = SystemColors.Info;
string s = ColorTranslator.ToHtml(c);

s = String.Format("#{0:x}{1:x}{2:x}", c.R, c.G, c.B);

Shawn B. said:
Greetings,

In creating a server control I added a property of type
System.Drawing.Color.

When the control is rendered, it generates a style that contains a style
called "backgroundColor" that will hold the value of
[Property].ToKnownColor.

It works well, except in some cases (if you set a system-defined color) such
as the "Info" color. When it renders, it simply renders "Info" but in the
style, that's not a known color. The MS controls render it as
"InfoBackground" but I can't see where I get that name from. It appears
that I have to know all these variations in the system-defined colors and
replace them with the proper name. Is there an easier built-in way?


Thanks,
Shawn
 

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

Members online

Forum statistics

Threads
473,769
Messages
2,569,580
Members
45,055
Latest member
SlimSparkKetoACVReview

Latest Threads

Top