How to Change Color Settings in Visual Basic

When it comes to color, the Visual Basic studio brings a rich set of tools to the table. The multiple approaches in VB give you the flexibility and potential for creating dynamic color applications. Here's how it works.

Instructions

  1. Using Pre-Formatted Colors

    • 1

      The color constants provided by Visual Basic let you plug in names of colors as properties of any given object or form. In fact, the colors are many times "drawn" on the form before run time. But you can also use conventions like vbRed, vbGreen and vbBlue to label color properties. Pick a Visual Basic color and find out if it is supported in your version.

    • 2

      Go to the properties code for your object.

    • 3

      Change the object color using a command like objBoink.color = vbRed

    Color as Hexadecimal

    • 4

      Figure out integers in the hexadecimal system. You may have to convert an integer from decimal to hexadecimal, which involves dividing the integer by 16 and using the product and the remainder. Basically, the hex system for colors uses a two-digit integer between 00 and FF, where each digit holds a value between 0 and 16 (F).

    • 5

      Now, the hexadecimal color will be three of these two-digit hex integers, one for each of the three primary colors red, green, and blue. Put all three integers together between two ampersands and an H: Ex: &H808080& is grey (a median value of all three colors).

    • 6

      Use your hexadecimal color to describe an object's color property.

    Dynamic Color with RGB

    • 7

      Visual Basic's most adaptable color feature is the RGB command. This deals with the three primaries discussed above. However, in an RGB command, VB can access the integers to change only one primary at a time, or to change in complex patterns using well-written functions. First, find or create the RGB command, which is each primarily represented as in integer between 0 and 255 (255 = total light intensity, 0 = low light intensity) & (Ex: 0,0,0 = black)

    • 8

      Within your RGB command, change one or more of the three integers to alter the color. Ex: for RGB (0,0,0) a change to the first integer results in (255,0,0) bright red.

    • 9

      Save code and check the object to see if the color is right. If not, go back into the RGB command and try again.

Tips & Warnings

  • You can write functions that change RGBs in any number of ways. It helps to practice with simple objects first to get a good idea of the "light" spectrum.

Related Searches:

Resources

Comments

You May Also Like

Related Ads

Featured