How do I get the color from a hexadecimal color code using .NET?

前端 未结 16 771
不思量自难忘°
不思量自难忘° 2020-11-22 06:45

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

16条回答
  •  伪装坚强ぢ
    2020-11-22 07:18

    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.

提交回复
热议问题