0

i am trying to get the Hex value of color that is passed as string. for example,

private string HexColor(string colorName) // like "Red"
{

 // returns hex value like "12345"
}

i got links for convert a Windows.UI.Color to its Hex value. but not for a string color name to color hex value. Thanks in advance for your help.

Update : For metro app

2

3 Answers 3

2

Color.fromName creates a Color structure from the specified name of a predefined color, then ToArgb:

Color.FromName(colorString).ToArgb().ToString("X8").Substring(2,6);

ToString("X8") creates the hexadecimal value as string from an integral type.

Sign up to request clarification or add additional context in comments.

Comments

0
Color c = Color.Red;
string hex = c.R.ToString("X2") + c.G.ToString("X2") + c.B.ToString("X2");

Comments

0

You can use this function

private string ConvertColorStringToHex(string colorString){
return Color.FromName(colorString).ToArgb().ToString("X8").Substring(2,6);
}

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.