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 SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Function to generate darker color (clBtnFace -> clBtnShadow)

Status
Not open for further replies.

indrahig

Programmer
Mar 23, 2004
63
0
0
ID
Hi,
We all know about system color in Delphi:
clBtnFace and clBtnShadow.

clBtnShadow is always darker than clBtnFace.
clBtnShadow is generated by Windows automatically when we change the clBtnFace (through display properties in windows control panel)

Is there any function or API function to generate that kind of Color?
I mean, we provide a Color, then the function return a darker Color than the provided color. The input Color and the result color relationship is just like clBtnFace and clBtnShadow.

Anyone knows that?
 
Colours are stored as a binary value each colour represented as 8 bits.
In hex this looks like
$FFFFFF (white) $000000 (black), there is an upper control byte which we dont need to worry about.

So to darken a colour simply decrese all three bytes by the same amout.
e.g
$FFFFFF decrese to $EEEEEE is a light grey.
$E7E7E7 slightly darker grey.

darkrning can be achived like this, load the result into the color property of whatever you want to alter.
BColour := Bcolour - $111111;


Steve: Delphi a feersum engin indeed.
 
wow, thanks whosrdaddy and sggaunt.
I'll try those and give you the result.
 
Here it is,
I decided to use this code (after some experiment)
Code:
function ChangeColor(AColor: TColor; Lighten: boolean): TColor;
var
  r,g,b: extended;
  aRGBCol: integer;
begin
  aRGBCol:= ColorToRGB(AColor);
  r := GetRValue(aRGBCol);
  g := GetGValue(aRGBCol);
  b := GetBValue(aRGBCol);
  if Ligthen then
  begin
    if r = 0 then
      r:= 127
    else
      r := r+((r/255)*100);
    if g = 0 then
      g:= 127
    else
      g := g+((g/255)*100);
    if b = 0 then
      b:= 127
    else
      b := b+((b/255)*100);
  end
  else
  begin
    r := r-((r/255)*100);
    g := g-((g/255)*100);
    b := b-((b/255)*100);
  end;
  if r > 255 then r := 255;
  if r < 0 then r := 0;
  if g > 255 then g := 255;
  if g < 0 then g := 0;
  if b > 255 then b := 255;
  if b < 0 then b := 0;
  Result := RGB(byte(Round(r)),byte(Round(g)),byte(Round(b)));
end;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top