
Help! VB's Palette at 256 Colors
Quote:
>In Visual Basic 6, when running in 256 colors, the choices I have available
>for selecting the BackColor (etc) for a form or control are limited far
>below the 256 colors the system palette actually supports. For example, I
Those are just the colors you can pick by clicking the color bar: you can
enter any color you like in the property browser as a hex value &HBBGGRR
(blue, green, red components, each 00 to FF).
Quote:
>want to set the back color of my forms to a shade of gray one step lighter
>than the traditional battleship grey. I can successfully import bmp files
>into image controls that have this shade of gray as part of the bitmap.
>However, the corresponding shade of gray that shows in the VB palette
>appears dithered. What gives? Is there a way around this? It appears the
>Windows OS itself limits the system colors available for window
backgrounds,
>etc., below 256 colors when the display has been set to 256 colors, though
>this does not apply to bitmaps and other graphics.
By default, VB forms use a standard 256-color palette called the "halftone
palette". If it doesn't contain your favorite color, it'll come out
dithered. You _can_ make that color come out undithered, however.
There are several ways to do this. The easiest is to make a 256-color
bitmap whose palette contains all the custom colors you need. It can be
just 1x1 pixel (it's the palette that's important, not the displayed
colors). Put a picturebox on your form and put it at the top of the ZOrder
(Tools\Format\Bring to Front, or PictureX.ZOrder in the Form_Load event).
Set the form's PaletteMode = UseZOrder. Now you can draw undithered colors.
A second method uses the same bitmap, but you set the PaletteMode = Custom,
and the form's Palette property to the bitmap. Now you can draw those
colors, but you need to use a bit of a trick. You set an additional bit in
the color specification:
Form1.BackColor = RGB(r, g, b) Or &H2000000
You can also address the palette colors by palette index:
Form1.BackColor = 42 Or &H1000000
will color the form with the 42nd color in the palette.
Jim Deutch
MS Dev MVP