@Jürg O An attempt with "perceived Luminance" (according to: https://www.w3.org/TR/AERT/#color-contrast )
Dim dVal As Double = (mColor.Red * 0.299) + (mColor.Green * 0.587) + (mColor.Blue * 0.114)
if (dVal <= 127.5) then
'Dark Background: Bright TextColor
colBestForText = &cFFFFFF
else
'Bright Background: Dark TextColor
colBestForText = &c000000
end if
Is this good enough - or what do you use?
thanks for the code above, Jürg Otter.
i have put this code into my application where user are allow to change the background color or the sidebar and check it is suitable for black or white.
i make it into a function and call it from the bevelbutton that open the color selector
Public Function TextColorBlackorWhite(mcolor as Color) as Color
Dim dVal As Double = (mColor.Red * 0.299) + (mColor.Green * 0.587) + (mColor.Blue * 0.114)
If (dVal <= 127.5) Then
'Dark Background: Bright TextColor
Return &cFFFFFF
Else
'Bright Background: Dark TextColor
Return &c000000
End If
End Function
If TextColorBlackorWhite(c) = kkWhite Then
MsgBox "You need a color that goes well with black color text"
Else
....
END IF