Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 661
Default How dark is a color

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
  #2   Report Post  
Posted to microsoft.public.excel.programming
external usenet poster
 
Posts: 2,452
Default How dark is a color

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" wrote in message
...
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
Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules

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


Similar Threads
Thread Thread Starter Forum Replies Last Post
How do I control the light/dark variations Excel 2007 color theme? RuthMor Excel Discussion (Misc queries) 6 November 23rd 10 11:30 PM
Colors too dark! BiT212 Excel Worksheet Functions 1 October 25th 09 02:29 AM
Colors too dark.... BiT212 Excel Discussion (Misc queries) 5 October 22nd 09 07:31 PM
A shot in the dark Rodney New Users to Excel 12 May 27th 05 01:48 AM
VBE dark red highlight Otto Moehrbach[_6_] Excel Programming 3 July 9th 04 04:43 PM


All times are GMT +1. The time now is 08:03 PM.

Powered by vBulletin® Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright ©2004-2024 ExcelBanter.
The comments are property of their posters.
 

About Us

"It's about Microsoft Excel"