How To Set a Custom Color in a VB6 Form

The following article debuted two years ago today on my company’s internal Twiki pages.


Have you ever wanted to set the color on a VB6 form to a custom value — to match the color of something else, for instance? This document:

  1. Describes the format VB6 controls expect you to use when entering color values
  2. Shows how to find the color value to use to match an existing color.

The Short Answer

Colors for VB6 controls are specified in the following format:

   &H00BBGGRR&

where RR, GG, and BB are two-digit RGB values in hexadecimal format. For instance, if you wanted a pure green color, you would pick &H0000FF00&:

R G B
00 FF 00

Finding the RGB Value

  1. Open the image file in MS-Paint. (If the color is on a control or something that you don’t have an image file for, take a screen shot by pressing the PrtScrn key, then paste it into MS-Paint.)
  2. Click the color picker in the tool box:
    1-rgb-color-picker
  3. Click the eyedropper mouse cursor on the color you want to pick up:
    2-rgb-pick-color
  4. Choose the Edit Colors… menu item on the Colors menu. Press the Define Custom Colors button:
    3-rgb-custom-colors
  5. The RGB values for the color you picked up will be shown in decimal:
    4-rgb-decimal-rgb-values
    For this example, the decimal RGB values are:

    Decimal RGB
    R G B
    242 55 14
  6. Convert the RGB values to two-digit hexadecimal numbers:
    Hexadecimal RGB
    R G B
    F2 37 0E
  7. Put the hexadecimal numbers in &H00BBGGRR& format: &H000E37F2&
  8. Plug this into the VB control property and see if it worked!
    5-rgb-set-color-in-control-props

— DanielMeyer – 16 Apr 2007

1 thought on “How To Set a Custom Color in a VB6 Form

  1. If you’re grabbing colors from webpages, there is Firefox plug-in that is extremely useful.

    It’s called ColorZilla (clever eh?) and it will give you an eye dropper tool to pick the color from anywhere in Firefox, on a webpage or even part of the Firefox UI. The values come back in the following form:

    R: 232, G: 233, B: 234 | #E8E9EA | ΔX: 500, ΔY: 324 |
    p.postmetadata

    There you have both the 0-255 RGB values plus the HTML hex color which can be split apart in RGB hex values (for this example R=E8, G=E9, and B=EA).

    Very useful.

Leave a comment

This site uses Akismet to reduce spam. Learn how your comment data is processed.