Using a Hexadecimal color instead of a System.Drawing.Color

A colleague asked me how to use a hexademical color on an object that requires a System.Drawing.Color. It's quite simple and I thought I'd share it.

As an example, you may define a background color using the System.Drawing.Color:

panRow.BackColor = Drawing.Color.Red

But you want a custom color, so you may instead use the ColorTranslator and define the Hex value: 

panRow.BackColor = System.Drawing.ColorTranslator.FromHtml("#FF5B5B")

This is true of all controls that require a System.Drawing.Color.

May your dreams be in ASP.NET!

Nannette

Shining Star Services LLC on LinkedIn

2 Comments

Comments have been disabled for this content.