Articles   Members Online:
-Article/Tip Search
-News Group Search over 21 Million news group articles.
-Delphi/Pascal
-CBuilder/C++
-C#Builder/C#
-JBuilder/Java
-Kylix
Member Area
-Home
-Account Center
-Top 10 NEW!!
-Submit Article/Tip
-Forums Upgraded!!
-My Articles
-Edit Information
-Login/Logout
-Become a Member
-Why sign up!
-Newsletter
-Chat Online!
-Indexes NEW!!
Employment
-Build your resume
-Find a job
-Post a job
-Resume Search
Contacts
-Contacts
-Feedbacks
-Link to us
-Privacy/Disclaimer
Embarcadero
Visit Embarcadero
Embarcadero Community
JEDI
Links
How to automatically set the font color according to the background color Turn on/off line numbers in source code. Switch to Orginial background IDE or DSP color Comment or reply to this aritlce/tip for discussion. Bookmark this article to my favorite article(s). Print this article
12-Oct-02
Category
Graphic
Language
Delphi 2.x
Views
169
User Rating
No Votes
# Votes
0
Replies
0
Publisher:
DSP, Administrator
Reference URL:
DKB
			Author: Jonas Bilinkevicius

How can I make the font color dependent from the background color? I want to make 
the color selection between white and black dependent from the background color.

Answer:

This seems to work pretty well, at least on a non-palette video mode:
1   
2   function InverseColor(color: TColor): TColor;
3   var
4     rgb_: TColorref;
5     function Inv(b: Byte): Byte;
6     begin
7       if b > 128 then
8         result := 0
9       else
10        result := 255;
11    end;
12  begin
13    rgb_ := ColorToRgb(color);
14    rgb_ := RGB(Inv(GetRValue(rgb_)), Inv(GetGValue(rgb_)), Inv(GetBValue(rgb_)));
15    Result := rgb_;
16  end;
17  
18  procedure TForm1.Button1Click(Sender: TObject);
19  begin
20    with colordialog do
21    begin
22      color := label1.color;
23      if execute then
24      begin
25        label1.color := color;
26        label1.font.color := InverseColor(color);
27      end;
28    end;
29  end;


			
Vote: How useful do you find this Article/Tip?
Bad Excellent
1 2 3 4 5 6 7 8 9 10

 

Advertisement
Share this page
Advertisement
Download from Google

Copyright © Mendozi Enterprises LLC