Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to change the shade of a color? 1

Status
Not open for further replies.

TimSNL

Programmer
Sep 11, 2001
119
AU
Hello,

I need to calculate the lighter/darker shade of a given color [afro2].

Example, The form is set to clBtnFace, I want to set some controls on the form to a color just a bit lighter than clBtnFace and some other controls to a color just a bit darker than clBtnFace. Without changing the color itself, just changing the shade of it.

I think I need to convert the D6 RGB color clBtnFace to HSL representation, then I could add/subtract from L (Luminosity), then convert back to RGB and assign to the color property of my control.

I have tried to use some RGBtoHSL converter procedures and they have not seemed to work as I expected. I would have thought that if I do RGBtoHSL, then without changing the numbers just do HSLtoRGB, then I would have ended up with the same color I started with. Nope, I get black??
[flush]

Has anyone ever tried anything like this?
Have you got any ideas which may help me?

Thanks.

Tim Dover
SNL Computing
 
I think that what's going wrong is that your RGBtoHSL routine is expecting an RGB value, and it's not getting one. Special values like clBtnFace are not internally represented as RGB values; they are special values which are then translated to RGB by Windows on the way to the display. Try:
Code:
    ShowMessage(IntToStr(clBtnFace));
, and you'll get -2147483633, which is $8000000F hex. You need to first convert clBtnFace to an RGB value, then use your HSL routines.

As a demo, try the following:
Code:
procedure TForm1.Button1Click(Sender: TObject);
var Colour: LongInt;
    s: string;
begin
    IdentToColor('clBtnFace', Colour);
    Colour := ColorToRGB(Colour);
    s := ColorToString(Colour);
    ShowMessage(s);
end;
The hex value you get displayed will, of course, vary depending on your Windows colour scheme.
 
Wow, THANKS rONIN441, this has fixed my problem [frog].

Thanks for your help, you made my day [bigsmile]
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top