Main Logo
Articles   Members Online:
-Article/Tip Search
-News Group Search over 800,000 Borland 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
Delphi: Calculate a contrasting text color to a background
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
Calculate a contrasting text color to a background 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
10-Aug-04
Category
Graphic
Language
Delphi All Versions
Views
635
User Rating
10
# Votes
1
Replies
1
Publisher:
Philipp, Steve
Reference URL:
www.HeuristicResearch.com
			1   
2   //If the user can change the background color of a component,
3   //make sure that the caption/text is displayed in a contrasting color.
4   
5   unit Unit1;
6   
7   interface
8   
9   uses
10    Windows, SysUtils, Graphics, Controls, Forms, StdCtrls, Buttons, ComCtrls,
11    Classes;
12  
13  type
14    TForm1 = class(TForm)
15      Edit1: TEdit;
16      BitBtn1: TBitBtn;
17      procedure BitBtn1Click(Sender: TObject);
18    end;
19  
20  var
21    Form1: TForm1;
22  
23  implementation
24  
25  {$R *.dfm}
26  
27  function ContrastColor(clBackground: TColor): TColor;
28  begin
29    with TRGBQuad(clBackground) do
30      if (rgbRed * 0.3) + (rgbGreen * 0.59) + (rgbBlue * 0.11) > 127.5 then
31        Result:= clBlack
32      else Result:= clWhite;
33  end;
34  
35  //To test:
36  procedure TForm1.BitBtn1Click(Sender: TObject);
37  begin
38    Edit1.Color:= Random(255) shl 16 + Random(255) shl 8 + Random(255);
39    Edit1.Font.Color:= ContrastColor(Edit1.Color);
40  end;
41  
42  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
Advertisement


Share this page
Advertisement
Copyright © 2017 by No Limit Solutions LLC