How to convert string to color

  • Thread starter Thread starter andie
  • Start date Start date
A

andie

Hi Guys,

Just wondering whether it is possible to convert a string into
System.Drawing.Colour object.

For example:

"Black" will match to System.Drawing.Color.Black, etc etc etc

I notice that it is possible using Color.FromName(string psName) in
..NET framework. Unfortunately, Color.FromName is not supported in .Net
Compact Framework.

The situation is as follow: We create an xml file that contains font
properties for all of the Controls. Then, we extract the color value
from the xml file and we need to convert this into Color object.

Regards,
Andie
 
Hey,

Thanks to opennetcf library. You can convert a string to a Color object
by calling:

string lsColor = "Blue"
Color loForeColor = (Color)
typeof(System.Drawing.Color).GetProperty(lsColor).GetValue(null, null);
 
I use the following XML structure and read each of the node and store
it to IDictionary<string, string> object for future reference. It is
equivalent with the use of Resource file.

<doc>
<res>
<data name="InfoLabelForeColor">
<value>Black</value>
<used>Y</used>
</data>
</res>
</doc>
 

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

Back
Top