Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

If Form is dark, then Text on form should be Light

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.

like image 657
jay_t55 Avatar asked Sep 29 '09 09:09

jay_t55


People also ask

What color text looks good on black background?

Black backgrounds: High-chroma colors are best for black backgrounds because they offer a good contrast ratio without the eye fatigue (which occurs with white text on a black background).

Is white text on black easier to read?

While white text on a black background provides very high value contrast, it is less readable and causes greater eye fatigue than black text on a white background.

Why is it easier to read white on black?

It'll reflect less light, making it easier to read. Keep in mind that if you're reading text in a dark room where no light is present, white text on a black background isn't as hard to read. This is because no light is reflecting off it in a dark room.

Is a black background accessible?

Pure black isn't harmful to all users. Low vision users, who are sight impaired but not blind, tend to read text better with pure black text or white text on a black background. When designing for them, you may need to use black for an accessibility mode.


2 Answers

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

like image 105
Jon Skeet Avatar answered Sep 30 '22 02:09

Jon Skeet


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.

like image 42
BvuRVKyUVlViVIc7 Avatar answered Sep 30 '22 02:09

BvuRVKyUVlViVIc7