How can I get a color from a hexadecimal color code (e.g. #FFDFD991
)?
I am reading a file and am getting a hexadecimal color code. I need to create the
I used ColorDialog in my project. ColorDialog sometimess return "Red","Fhushia" and sometimes return "fff000". I solved this problem like this maybe help someone.
SolidBrush guideLineColor;
if (inputColor.Any(c => char.IsDigit(c)))
{
string colorcode = inputColor;
int argbInputColor = Int32.Parse(colorcode.Replace("#", ""), NumberStyles.HexNumber);
guideLineColor = new SolidBrush(Color.FromArgb(argbInputColor));
}
else
{
Color col = Color.FromName(inputColor);
guideLineColor = new SolidBrush(col);
}
InputColor is the return value from ColorDialog.
Thanks everyone for answer this question.It's big help to me.