Wednesday, April 22, 2009

Gdk.Color -> HTML hex string

String.Format("#{0:X2}{1:X2}{2:X2}", (byte)(colorSelector.CurrentColor.Red >> 8), (byte)(colorSelector.CurrentColor.Green >> 8), (byte)(colorSelector.CurrentColor.Blue >> 8));


or a better way:

currentEntry.Text = String.Format("#{0:X2}{1:X2}{2:X2}", (int)Math.Truncate(colorSelector.CurrentColor.Red / 256.00), (int)Math.Truncate(colorSelector.CurrentColor.Green / 256.00), (int)Math.Truncate(colorSelector.CurrentColor.Blue / 256.00));

2 comments: