I don't believe there is any reliable method for what you want.
Heres a selection of methods (in VB) each of which has their own problems.
Private Function InvertColor(ByVal ColorIn As Color) As Color
Return Color.FromArgb(ColorIn.ToArgb Xor &HFFFFFF)
End Function
Private Function ContrastingColor(ByVal ColorIn As Color) As Color
If MidRange(ColorIn) Then Return Color.White
Return InvertColor(ColorIn)
End Function
Private Function MidRange(ByVal ColorIn As Color) As Boolean
Return ColorIn.R > 100 AndAlso ColorIn.R < 160 AndAlso _
ColorIn.G > 100 AndAlso ColorIn.G < 160 AndAlso _
ColorIn.B > 100 AndAlso ColorIn.B < 160
End Function
Private Function BlackOrWhite(ByVal colorin As Color) As Color
If colorin.GetBrightness < 0.5 Then
Return Color.White
End If
Return Color.Black
End Function
--
Mick Doherty
http://dotnetrix.co.uk/nothing.html
"sam" <sa*@discussions.microsoft.com> wrote in message
news:08**********************************@microsof t.com...
Hi
Is there a method, or has anybody already ready written one to determine
a
contrasting color to a background color for text. In my case during a
paint
of a cell in a data grid.
Thanks