Landiin
asked on
setting fonts color in RGB
How would i change the font color if i only wanted to change the red value in the rgb value and the same for green and blue..
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
is there not a
function RGBToColor(R:Byte;G:Byte;B :Byte) : TColor;
?
function RGBToColor(R:Byte;G:Byte;B
?
No, there's a ColorToRGB withi will take a TColor and convert a system color to a RGB color if needed. And it would not help to *change* just a part of a color.
ASKER
there is no RGBToColor function that i have found..
was just a guess,
no delphi on hand yet
:-)
no delphi on hand yet
:-)
label1.font.Color:=rgb(0,0 ,255);
If i am understanding you correctly, you want to change each rgb value indepently with out changing the other 2 e.g change red without changing the green and blue values. You could do it like this:
function ChangeColor(FColor : TColor; R, G, B : Integer) : TColor;
var
I : Integer;
Red, Green, Blue : Byte;
begin
I := ColorToRGB(FColor);
I := Integer(GetNearestColor(FC olor, I));
if R >= 0 then Red := R else Red := GetRValue(I);
if G >= 0 then Green := G else Green := GetGValue(I);
if B >= 0 then Blue := B else Blue := GetBValue(I);
Result := RGB(Red, Green, Blue);
end;
procedure TForm1.Button1Click(Sender : TObject);
begin
Label1.Font.Color := ChangeColor(Label1.Font.Co lor, 255, -1, -1);
end;
the colors you dont want to change have to have a integer below 0 when calling to the function so that it knows you don't want to change them. The example shown above will keep the Green and Blue values the same and will just change the red value.
Cheers,
Alan
function ChangeColor(FColor : TColor; R, G, B : Integer) : TColor;
var
I : Integer;
Red, Green, Blue : Byte;
begin
I := ColorToRGB(FColor);
I := Integer(GetNearestColor(FC
if R >= 0 then Red := R else Red := GetRValue(I);
if G >= 0 then Green := G else Green := GetGValue(I);
if B >= 0 then Blue := B else Blue := GetBValue(I);
Result := RGB(Red, Green, Blue);
end;
procedure TForm1.Button1Click(Sender
begin
Label1.Font.Color := ChangeColor(Label1.Font.Co
end;
the colors you dont want to change have to have a integer below 0 when calling to the function so that it knows you don't want to change them. The example shown above will keep the Green and Blue values the same and will just change the red value.
Cheers,
Alan
ASKER
Thx for all the fast good good comments. I had to go with
Baksa because that comment made me come up with this:
Label1.Font.Color := StrToInt('$00'+IntToHex(Re d,2)+IntTo Hex(Green, 2)+IntToHe x(Blue,2)) ;
Thx for the push in the correct direction Baksa
Baksa because that comment made me come up with this:
Label1.Font.Color := StrToInt('$00'+IntToHex(Re
Thx for the push in the correct direction Baksa
Landiin, this solutions of yours is about the worst you could come up with; converting numeric values to hex strings, concatenating them back together and converting it back to a numberic value is VERY inefficient. Baska's solution was *much* better, and mine (posted first also) would probably have been the fastest with no computations whatsoever.
ASKER
AvonWyss you are correct about all the converting. It was just to simple to pass up, ans speet didn't matter. I am just starting out with delphie and programming all together. I didn't understand your comment but I am sure its the fastest, I wouldn't know. All in all you all help a great deal and I learned something... thx again
ASKER
after trying all of yalls exp. I should of used f15iaf his was was so easy
rbgRed:=255; //ranges 0..255
// rbgBlue:=10;
// rbgGreen:=10;
end;