355 words
2 min
Quick Tip Color Objects From Hex Codes In Net

Hex Palette .Net provides a wonderful class called the color class. There are plenty of predefined colors in it that make it easy when you want to set the color of a label or background quickly and easily. Sometimes though, you need to have a little more control on the color you’re working with. Having dabbled in the web realm for so long, hex codes are my friend. So when I discovered I couldn’t simply set the ForeColor property of my label webcontrol using Hex values. I was a bit frustrated and stumped.

Fortunately, the Color class itself came to the rescue! They provide a translator class that allows you to easily work hex code into your labels. To start, simply import the System.Drawing library into your class. From there, do something like this:

lblAppName.ForeColor = ColorTranslator.FromHtml("#DEDBEF");

You’ll get a nice shade of light blue, err, off white, err, periwinkle using that code above. What’s really nice is that the ColorTranslator is a shared class, so you don’t even need to instantiate an instance of the object to use it. Enjoy!

Hex Palette .Net provides a wonderful class called the color class. There are plenty of predefined colors in it that make it easy when you want to set the color of a label or background quickly and easily. Sometimes though, you need to have a little more control on the color you’re working with. Having dabbled in the web realm for so long, hex codes are my friend. So when I discovered I couldn’t simply set the ForeColor property of my label webcontrol using Hex values. I was a bit frustrated and stumped.

Fortunately, the Color class itself came to the rescue! They provide a translator class that allows you to easily work hex code into your labels. To start, simply import the System.Drawing library into your class. From there, do something like this:

lblAppName.ForeColor = ColorTranslator.FromHtml("#DEDBEF");

You’ll get a nice shade of light blue, err, off white, err, periwinkle using that code above. What’s really nice is that the ColorTranslator is a shared class, so you don’t even need to instantiate an instance of the object to use it. Enjoy!

Quick Tip Color Objects From Hex Codes In Net
https://dillieo.me/posts/development/2011-03-28-quick-tip-color-objects-from-hex-codes-in-net/
Author
Sean Patterson
Published on
2011-03-28
License
CC BY-NC-SA 4.0