How To Set a Custom Color in a VB6 Form
Posted by danielmeyer on April 16, 2009
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:
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&:
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