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 ...

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.