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:
- Describes the format VB6 controls expect you to use when entering color values
- 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
- 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.)
- Click the color picker in the tool box:
- Click the eyedropper mouse cursor on the color you want to pick up:
- Choose the Edit Colors… menu item on the Colors menu. Press the Define Custom Colors button:
- The RGB values for the color you picked up will be shown in decimal:
For this example, the decimal RGB values are:Decimal RGB R G B 242 55 14 - Convert the RGB values to two-digit hexadecimal numbers:
Hexadecimal RGB R G B F2 37 0E - Put the hexadecimal numbers in &H00BBGGRR& format: &H000E37F2&
- Plug this into the VB control property and see if it worked!
— DanielMeyer – 16 Apr 2007
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.