Solved

Color to fade from bright red to dark red with RGB-function

Posted on 2003-10-26
2
445 Views
Last Modified: 2012-05-04
Hi,
I think this a quite easy question for an expert, but I do not manage it:
In a database I have a field where items are in that are awaited for a certain date. If the items are not back by that date the row is paint in red. Now I want that the color is not only red but a certain tone of red depending on the days the item is not in time for ex. the item is in delay for 100 days, the row is dark red, for 50 days a lighter red and so on. I tried with: brush.color:= RGB(255,0,0) and that's OK only with red. How must I insert the RGB-values to have different shades of red ?
0
Comment
Question by:SCHUCla74
  • 2
2 Comments
 
LVL 8

Expert Comment

by:gmayo
ID: 9622474
255 is full brightness, 0 is nil. So use a value in between 0 and 255 for varying degrees of brightness. If you only use the first value, that is the red. Use a calculation to get degrees of redness for number of days.

Example:
if (DaysLate <= 0) then begin
   Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
   Brush.Color := RGB(Round(((100-DaysLate)/100) * 255), 0, 0);
end else begin
   Brush.Color := clBlack;
end;

Which gives a white background if DaysLate is zero or less, varying degrees of red to black for 1 - 100 days late, and black for over 100 days late. Alter to suit your requirements.

Geoff M.
0
 
LVL 8

Accepted Solution

by:
gmayo earned 100 total points
ID: 9622475
Actually, maybe you mean white to red. In which case that should be:
if (DaysLate <= 0) then begin
  Brush.Color := clWhite;
end else if (DaysLate <= 100) then begin
  v := Round(((100-DaysLate)/100) * 255);
  Brush.Color := RGB(255, v, v);
end else begin
  Brush.Color := clRed;
end;

Geoff M.
0

Featured Post

Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

A lot of questions regard threads in Delphi.   One of the more specific questions is how to show progress of the thread.   Updating a progressbar from inside a thread is a mistake. A solution to this would be to send a synchronized message to the…
Creating an auto free TStringList The TStringList is a basic and frequently used object in Delphi. On many occasions, you may want to create a temporary list, process some items in the list and be done with the list. In such cases, you have to…
A short tutorial showing how to set up an email signature in Outlook on the Web (previously known as OWA). For free email signatures designs, visit https://www.mail-signatures.com/articles/signature-templates/?sts=6651 If you want to manage em…

828 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