I need the hexadecimal string of color so I am using ColorTranslator.ToHtml() property which returns string hex of Color.
If I choose a random color it returns “#FFF0B6” etc. However, if I choose a system-defined color for example Color.Black it returns “Black” in string.
I need hexadecimal color codes in string whether they are defined in system or not. Any suggestions?
I have found this extension method worked well for me:
According to MSDN, that is indeed what
ColorTranslator.ToHtml()is intended to do.