Convert System.Drawing.Color into Hex String

Posted on: Wed Mar 18 18:02:04 -0700 2009. Updated on: Wed Mar 18 18:02:38 -0700 2009.
Category: DotNet

This comes in handy sometimes. Use it to turn a Color object into an HTML compatible Hex string that the browser can understand.

private string ConvertColorToHex(Color color)
		{
			string hexColor = color.R.ToString("X") + color.G.ToString("X") + color.B.ToString("X");
			return hexColor;
		}

Comments:

Add a Comment:

simple_captcha.jpg
(human authentication)


Ads

Categories

About

Random foliage

This website is meant to be a reference for ASP Dot Net developers. The entries are a compilation of things I've figured out how to do and that I deem useful to keep of track for future reference. Assumptions: web development with: C Sharp (vb sucks), visual studio 05/08, .net 3.5, meant for programmers. Written by: James Reategui.