| Calculating a Contrasting Color Code | |||||||||||||||||||
| With Peter Zilahy Ingerman | |||||||||||||||||||
This week's article is something different. It's a strange journey into the subject of what programming is REALLY like. The journey features side trips to hex and decimal numbers, calculation with logical operations, the value of Object Oriented Programming, and some philosophy about systems development methodology. |
|||||||||||||||||||
In the About Visual Basic Forum recently, a reader asked the question I need to display text in a label whose background color is determined by the user. So I have no control whatsoever over the color they choose. The problem is that the text in the label is not always legible if the color is set at design time because it may not contrast with the color the user selected! The process of working on this problem uncovered some core programming principles. Most technical articles are designed to tell you something specific about what should be in the final product: the completed program. But they don't tell you much about the real process of writing a program. Programming is usually an excercise in finding out what doesn't work over and over before finally writing the code that does work. And programs that do work can always be improved. Even though this article shows that I didn't "see the obvious" at a few points, the step-by-step story here, with bugs uncovered and explained, has important lessons for every working programmer. The question in the Forum noted that an idea for solving the problem that had already been tried was "making Forecolor the inverse of Backcolor."
new_color = &HFFFFFF - old_color "This works OK if the label is almost black or almost white, but when the background is say, a darkish purple-mauve, the text becomes a murky grey that is almost impossible to read!! Is there some standard way of generating ready-to-read complementary colors?" |
|||||||||||||||||||

