Visual Basic Concepts
Visual Basic supports 256 colors on systems with video adapters and display drivers that handle 256 or more colors. The ability to display 256 simultaneous colors is particularly valuable in multimedia applications or applications that need to display near –photographic-quality images.
You can display 256-color images and define up to 256 colors for graphics methods in:
Note Support for 256 colors does not apply to Windows metafiles. Visual Basic displays metafiles using the default palette of 16 VGA colors.
Color palettes provide the basis for 256-color support in Visual Basic applications. In discussing palettes, it’s important to understand the relationship between different palette types. The hardware palette contains 256 entries defining the actual RGB values that will be displayed on screen. The system halftone palette is a predefined set of 256 RGB values made available by Windows itself. A logical palette is a set of up to 256 RGB values contained within a bitmap or other image.
Windows can draw using the 256 colors in the hardware palette. Twenty of these 256 colors, called static colors, are reserved by the system and cannot be changed by an application. Static colors include the 16 colors in the default VGA palette (the same as the colors defined by Visual Basic’s QBColor function), plus four additional shades of gray. The system halftone palette always contains these static colors.
The foreground window (the window with focus) determines the 236 nonstatic colors in the hardware palette. Each time the hardware palette is changed, all background windows are redrawn using these colors. If the colors in a background window’s logical palette don’t perfectly match those currently in the hardware palette, Windows will assign the closest match.
Forms, picture boxes, and image controls automatically display images in 256 colors if the user’s display hardware and software can support that many colors on screen. If the user’s system supports fewer colors than the image, then Visual Basic will map all colors to the closest available.
On true-color (16-million color) displays, Visual Basic always uses the correct color. On monochrome or 16-color displays, Visual Basic will dither background colors and colors set with the FillColor property. Dithering is a process used to simulate colors not available from the video adapter and display driver.
With 256-color video drivers, you can use up to 256 colors with graphics methods. By default, the 256 colors available in Visual Basic are those in the system halftone palette. Although you can specify an exact color using the RGB function, the actual color displayed will be the closest match from the halftone palette, as shown in Figure 12.22.
Figure 12.22 Color matching from a specified color to the display
Although the default palette for Visual Basic is the system halftone palette, you can also control the display of colors with the PaletteMode and Palette properties of forms, user controls, and user documents. In this case, the color match is much the same, except that colors will be matched to the closest color in the hardware palette.
For More Information To learn more about the Palette and PaletteMode properties, see "Managing Multiple Color Palettes" later in this chapter.