PC Review


Reply
Thread Tools Rate Thread

How dark is a color

 
 
Paul
Guest
Posts: n/a
 
      29th Oct 2009
How do I ascertain how dark a selected color is ?

I want to amend the font color of a form to complement the backcolor
selected by the user - i.e. white font on dark backgrounds, black font on
light backgrounds
 
Reply With Quote
 
 
 
 
RB Smissaert
Guest
Posts: n/a
 
      29th Oct 2009
This function seems to work very well:

Function GetContrastingFont(lClr As Long) As Long

'returns a contrasting font colour, given a long colour
'------------------------------------------------------
Dim R As Long
Dim G As Long
Dim B As Long

B = Int(lClr / 65536)
G = Int((lClr Mod 65536) / 256)
R = Int(lClr Mod 256)

'calculation from Peter Thornton
'-------------------------------
If R * 0.206 + G * 0.679 + B * 0.115 > 135 Then
GetContrastingFont = vbBlack
Else
GetContrastingFont = vbWhite
End If

End Function


RBS



"Paul" <(E-Mail Removed)> wrote in message
news:6B0BE3FB-4613-4206-91E9-(E-Mail Removed)...
> How do I ascertain how dark a selected color is ?
>
> I want to amend the font color of a form to complement the backcolor
> selected by the user - i.e. white font on dark backgrounds, black font on
> light backgrounds


 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
color transition (color changes from dark color to light color) color transition Microsoft Powerpoint 2 21st Nov 2009 12:21 PM
XP Color theme with dark window background color? danr_18@yahoo.com Windows XP Customization 2 25th Dec 2006 04:57 AM
I got my web cam hooked up and now the color is too dark =?Utf-8?B?bG91bHN0aWNrNjk=?= Windows XP Games 1 18th Oct 2004 02:11 AM
Re: My Screen Color Is Way To Dark Bob I Microsoft Windows 2000 0 2nd Jul 2004 06:42 PM
Color - light to dark Barbara Microsoft Powerpoint 4 12th May 2004 02:29 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 09:44 PM.