Convert TColor -> HTML  

Send By: Radikal (Q3 Team)
Web : http://www.q3.nu
Email: radikal@q3.nu
Date: 11/10/99

Tip accessed 482 times

 


Useful for convert Delphi colors to HTML colors

An example:

  • Put a TColorDialog (ColorDialog1), a TLabel (Label1) and a TButton (Button1) in your form
  • Put this code in the OnCLick of Button1:


     procedure TForm1.Button1Click(Sender: TObject);
    
     function ColorToHtml(DelphiColor:TColor):string;
     var
       tmpRGB : TColorRef;
     begin
       tmpRGB := ColorToRGB(DelphiColor);
       Result:=Format( '#%.2x%.2x%.2x',
                       [GetRValue(tmpRGB),
                        GetGValue(tmpRGB),
                        GetBValue(tmpRGB)]);
     end;
    
    
     begin
       if ColorDialog1.Execute then
         Label1.Caption:=ColorToHtml(ColorDialog1.Color);
     end;