Dgameman1 Dgameman1 - 11 months ago 36
C# Question

Not sure how to convert this to Hex?

This is the pseudo code I have written

Color temp = Color.FromArgb(Settings.Default["accentColorSetting"].ToString() + "200");
statusInfo.ForeColor = Color.FromArgb(temp.R, temp.G, temp.B);//(R, G, B)

The part that is the issue is
Color temp = Color.FromArgb(Settings.Default["accentColorSetting"].ToString() + "200");

The text inside
and it is a

The is the code I'm looking at
MaterialSkin Code

I already have it all setup and working, this is the only part I'm having trouble with now.

From what I understand,
Color temp = Color.FromArgb(Settings.Default["accentColorSetting"].ToString() + "200");
requires a Hex color to be placed, so it would take the string that inside the setting, which would be
and then the Materialskin code that I linked shows this
Orange200 = 0xFFAB40,
So I would like for it to replace

Any ideas on how to do this?

Answer Source

This is what you need to do:

string colorString = Settings.Default["accentColorSetting"].ToString() + "200";
Accent colorEnum;
Enum.TryParse(colorString, out colorEnum);
statusInfo.ForeColor = Color.FromArgb((int)colorEnum);

First, find the enum that corresponds to your string, and then simply use that value to obtain the corresponding Color.

No hex involved actually. Those enums are all integers, it's just that they are written in hex for simpler visual understanding, but they are nothing more than numeric values. You can do (int)Primary.BlueGrey50 for example and you will see its corresponding numeric value.