Mega Code Archive

 
Categories / Delphi / LAN Web TCP
 

Converting a tcolor value to a html color string

Question: How can I convert a TColor value to a HTML Color string? Answer: The following example demonstrates converting a TColor to a RGB color, and formating the RGB color to be shown as hexadecimal digits. procedure TForm1.Button1Click(Sender: TObject); var TheRgbValue : TColorRef; begin if ColorDialog1.Execute then begin TheRgbValue := ColorToRGB(ColorDialog1.Color); ShowMessage(Format('%.2x%.2x%.2x', [GetRValue(TheRGBValue), GetGValue(TheRGBValue), GetBValue(TheRGBValue)])); end; end;