I think i have made a mistake.
I am using the ChooseColor API to get the Color Commondialog which returns a long. Thats the number i want to check to see if it was light or dark, or is there an easy way to strip out the RGB number from that? I remember seeing something like this a while ago, but i can't remember where it was.
I'll look into that first. The number is the number you get when you do
Msgbox Form1.BackColor
Thats what i need to split into RGB, then figger out if its light or dark. How about Hex, would it be easier to find out if i had the hex values??
BW :cool:
I used this function & experimented.
Ihad the same problem in an application for which the user was allowed to fiddle with background colors in a text box. I used the following function to obtain an average color value.
Code:
Public Function ColorIntensity(ColorValue As Long) _
As Integer
Dim J As Integer
Dim X(1 To 4) As Integer
Dim TotalIntensity As Integer
Dim HexString As String
Dim HexNumber As Long
HexNumber = ColorValue
For J = 1 To 4
X(J) = HexNumber Mod 256
HexNumber = (HexNumber - X(J)) / 256
Next J
TotalIntensity = X(1) + X(2) + X(3)
ColorIntensity = TotalIntensity / 3
End Function
I experiemented a bit and used the following in the main line.
Code:
If ColorIntensity(BackGroundColor) < 85 _
Or BackGroundColor = vbBlue Then
txtBname(TextSlot).ForeColor = vbYellow
Else
txtBname(TextSlot).ForeColor = vbBlack
End If
You might find that some other average value suits your fancy. A lot of my users chose vbBlue, on which black type was hard to read. Otherwise, my cutoff of 85 worked okay.
BTW: The For loop could be 1 to 3 instead of 1 to 4. It worked, so I never fixed it.