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

Chapter 4 - Working With Menus and Dialog Boxes - Part 2

By Dan Mabbutt, About.com

5 of 5

Representing Colors in Code

Custom Colors - Manual ForeColor

Custom Colors - Manual ForeColor

In Visual Basic 6.0, colors were represented by a Long data type value but in VB.NET, colors are objects like everything else. You can use the FromOle and ToOle methods to translates VB.NET Color objects to and from the Long data type.

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim myColor As Color
Dim oleColor As Integer
myColor = ColorDialog1.Color
oleColor = ColorTranslator.ToOle(myColor)
~~~~~~~~~~~~~~~~~~~~~~~~~

Although it's VB 6, you might enjoy reading about how these numbers could be manipulated and calculated in the About Visual Basic article Calculating a Contrasting Color Code.

But wait! There's More!

VB.NET adds a whole new feature called the alpha component. Alpha lets you create transparent graphics! If you want to specify an alpha component, use the Color.FromArgb method and add a new argument ranging from 0 to 255 in front of the RGB numbers.

~~~~~~~~~~~~~~~~~~~~~~~~~
Dim myColor as Color myColor = Color.FromArgb(127, 23, 56, 78)
~~~~~~~~~~~~~~~~~~~~~~~~~

Just as we save desert for the end of the meal, the completed version of the Music Trivia program we started in Chapter 1 is presented at the end of this lesson on the next page ...

Index: Chapter 4 - Working With Menus and Dialog Boxes - Part 2

  1. Dates and Times - They're objects too!
  2. More on Date Data Types
  3. Add a little color to your programming!
  4. Back to Colors ...
  5. Representing Colors in Code

5 of 5

Explore Visual Basic

More from About.com

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

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

All rights reserved.