System.Drawing.ColorTranslator class has some static methods that can be used to convert to/from HTML colors and the
System.Drawing.Color object for that color in C# other .NET languages. There are times when this task is necessary, and it’s somewhat of a little known feature within the
To convert from an HTML color code to
System.Drawing.Color, use the following:
To convert from
System.Drawing.Color to an equivalent HTML color code, use the following:
Here is a small C# example of how to convert a
System.Drawing.Color to the HTML color format (Hex value or HTML color name value) and back.
// Convert from HTML color System.Drawing.Color c = System.Drawing.ColorTranslator .FromHtml("#F5F7F8"); // Convert to HTML color String strHtmlColor = System.Drawing.ColorTranslator .ToHtml(c);
Hopefully this helps you with the color code conversions you are needing to perform within your applications.
- 10 Oct 2020
- 01 Jul 2020
- 06 Apr 2020
- 11 Mar 2020
- 15 Feb 2020
Recent on Build5Nines.com
- 04 Dec 2020
Latest Cloud News: Apple on K8s, IoT, Microsoft Pluton and more! (November 20, 2020 Build5Nines Weekly)20 Nov 2020
Latest Cloud News: .NET 5 Released, Apple Silicon M1 CPU, and more! (November 12, 2020 Build5Nines Weekly)12 Nov 2020
- 11 Nov 2020
Latest Cloud News: Kubernetes, Terraform, Teams Multi-Login and more! (November 5, 2020 Build5Nines Weekly)05 Nov 2020
This site is a participant in the Amazon Services LLC Associates Program, an affiliate advertising program designed to provide a means for sites to earn advertising fees by advertising and linking to Amazon.com. We also participates in affiliate programs with Udemy, and other sites. This site is compensated for referring traffic and business to these companies.