views:

76

answers:

2

Hey All, :)

I have 60% Opaque form. And when the user changes the color of the form, sometimes (depending on the chosen color), they cannot see the text on the form anymore because it too-closely resembles the color of the form. So, I'm trying to do maybe an if/switch to see if the chosen BackColor of the form is either Dark, or Light. If it is Dark, then all text on the form should be White. If it is Light, then all text on the form should be Black.

Is this at all possible? I've seen this all over the place but not sure what to search for without writing the whole question in the search field.

Any help/suggestions would be greatly appreciated.

Thanks, jason.

+3  A: 

How about using Color.GetBrightness() to work out how light it is?

Jon Skeet
Thank you @Jon. Much appreciated. :)
baeltazor
+1  A: 

You could check, if the sum of the three rgb-values are above the half of the max-value

-> because 255,255,255 == white(light) and 0,0,0 == black(dark) :

f.e.

R 255
G 140
B 170
=====
  565

Max: 765 (Middle 382) Sum: 565

Because the sum is 565 and above the middle (dark < 382 < light), the color is light. So you can change the textcolor to dark.

Lichtamberg
Thank you @Lichtamberg, I was originally thinking of this but then managed to convince myself that it wouldn't work. But it does, much appreciated.
baeltazor