Solved

setting fonts color in RGB

Posted on 2001-09-17
12
422 Views
Last Modified: 2013-12-03
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..
0
Comment
Question by:Landiin
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
  • 2
  • +3
12 Comments
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6487720
with TRGBQuad(YourColor) do begin
    rbgRed:=255; //ranges 0..255
//    rbgBlue:=10;
//    rbgGreen:=10;
end;
0
 
LVL 1

Accepted Solution

by:
Baksa earned 50 total points
ID: 6487732

  rgb := (red * $10000) + blue *$100 + green;

  red := (rgb and $FF0000) div $10000;
  blue := (rgb and $FF00) div $100;
  green := rgb and $FF;
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6487743
is there not a
function RGBToColor(R:Byte;G:Byte;B:Byte) : TColor;
?
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 14

Expert Comment

by:AvonWyss
ID: 6487758
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.
0
 

Author Comment

by:Landiin
ID: 6487759
there is no RGBToColor function that i have found..
0
 
LVL 27

Expert Comment

by:kretzschmar
ID: 6487773
was just a guess,
no delphi on hand yet
:-)
0
 
LVL 3

Expert Comment

by:f15iaf
ID: 6487834
label1.font.Color:=rgb(0,0,255);
0
 
LVL 5

Expert Comment

by:alanwhincup
ID: 6487931
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(FColor, 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.Color, 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
0
 

Author Comment

by:Landiin
ID: 6487989
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(Red,2)+IntToHex(Green,2)+IntToHex(Blue,2));

Thx for the push in the correct direction Baksa
0
 
LVL 14

Expert Comment

by:AvonWyss
ID: 6488017
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.
0
 

Author Comment

by:Landiin
ID: 6488081
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
0
 

Author Comment

by:Landiin
ID: 6488721
after trying all of yalls exp. I should of used f15iaf his was was so easy
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever had your Delphi form/application just hanging while waiting for data to load? This is the article to read if you want to learn some things about adding threads for data loading in the background. First, I'll setup a general applica…
Introduction I have seen many questions in this Delphi topic area where queries in threads are needed or suggested. I know bumped into a similar need. This article will address some of the concepts when dealing with a multithreaded delphi database…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…

717 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question