1. Home
  2. Computing & Technology
  3. Visual Basic
Calculating a Contrasting Color Code
    With Peter Zilahy Ingerman
The Contrasting Background App

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.


 More of this Feature
• Part 2: The First Solution Attempt
• Part 3: The Second Solution Attempt
• Part 4: The First Bug
• Part 5: Symbolic Logic in Visual Basic
• Part 6: The Second Bug and VB .NET
• Part 7: Lessons Learned
 
 Join the Discussion
Is this the kind of article that helps you?
Let us know!
 
 Related Resources
• Beginning Visual Basic
• Visual Basic 6
 
 Elsewhere on the Web
• A short intro to binary numbers
• Binary, Decimal, and Logic
• Color Differences
VB 6 versus VB .NET

 

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?"

Next page > The First Solution Attempt > Page 1, 2, 3, 4 5, 6, 7
Explore Visual Basic
By Category
About.com Special Features

Stay connected and entertained with reviews on tips on the latest HDTVs, cellphones and more. More >

Easy ways to connect two computers for networking purposes. More >

  1. Home
  2. Computing & Technology
  3. Visual Basic

©2009 About.com, a part of The New York Times Company.

All rights reserved.