|
|
 |
 |
To access the contents, click the chapter and section titles.
Visual Basic 6 Black Book
(Publisher: The Coriolis Group)
Author(s): Steven Holzner
ISBN: 1576102831
Publication Date: 08/01/98
Setting Colors
Here are some commonly used properties you can specify colors for and what they mean:
- BackColorThe background color of the control or form.
- ForeColorThe drawing color used to draw figures and text.
- BorderColorThe color of the border.
- FillColorThe color you want the figure filled in with.
To set color properties like these in Visual Basic, you need to know how to set colors in general. There are four ways to do that:
- Using the RGB function
- Using the QBColor function to choose one of 16 Microsoft QuickBasic colors
- Using one of the intrinsic Visual Basic color constants
- Entering a color value directly
Well use the RGB function most often to specify colors. This function takes three colors values, 0 to 255, to specify the red, green, and blue values in the color you want like this: RGB(RRR, GGG, BBB), where RRR, GGG, and BBB are the red, green, and blue color values, respectively.
Here are some examples showing how to use this function and the color created:
RGB(255, 0, 0) 'Red
RGB(0, 255, 0) 'Green
RGB(0, 0, 255) 'Blue
RGB(0, 0, 0) 'Black
RGB(255, 255, 255) 'White
RGB(128, 128, 128) 'Gray
The QBColor function returns one of these colors when you pass it the matching numbers, 0 to 15:
- Black0
- Blue1
- Green2
- Cyan3
- Red4
- Magenta5
- Yellow6
- White7
- Gray8
- Light blue9
- Light green10
- Light cyan11
- Light red12
- Light magenta13
- Light yellow14
- Light white15
You can also use one of the built-in Visual Basic color constants, like vbRed, to specify a color. The standard Visual Basic color constants appear in Table 18.1. If you dig hard enough, you can even find the colors Visual Basic uses for system objects; these values appear in Table 18.2.
Table 18.1 Visual Basic color constants.
| Constant
| Value
| Description
|
| vbBlack
| &H0
| Black
|
| vbRed
| &HFF
| Red
|
| vbGreen
| &HFF00
| Green
|
| vbYellow
| &HFFFF
| Yellow
|
| vbBlue
| &HFF0000
| Blue
|
| vbMagenta
| &HFF00FF
| Magenta
|
| vbCyan
| &HFFFF00
| Cyan
|
| vbWhite
| &HFFFFFF
| White
|
Table 18.2 System color constants.
| Constant
| Value
| Description
|
| vbScrollBars
| &H80000000
| Scroll bar color
|
| vbDesktop
| &H80000001
| Desktop color
|
| vbActiveTitleBar
| &H80000002
| Color of the title bar for the active window
|
| vbInactiveTitleBar
| &H80000003
| Color of the title bar for the inactive window
|
| vbMenuBar
| &H80000004
| Menu background color
|
| vbWindowBackground
| &H80000005
| Window background color
|
| vbWindowFrame
| &H80000006
| Window frame color
|
| vbMenuText
| &H80000007
| Color of text on menus
|
| vbWindowText
| &H80000008
| Color of text in windows
|
| vbTitleBarText
| &H80000009
| Color of text in caption, size box, and scroll arrow
|
| vbActiveBorder
| &H8000000A
| Border color of active window
|
| vbInactiveBorder
| &H8000000B
| Border color of inactive window
|
| vbApplicationWorkspace
| &H8000000C
| Background color of multiple document interface (MDI) applications
|
| vbHighlight
| &H8000000D
| Background color of items selected in a control
|
| vbHighlightText
| &H8000000E
| Text color of items selected in a control
|
| vbButtonFace
| &H8000000F
| Color of shading on the face of command buttons
|
| vbButtonShadow
| &H80000010
| Color of shading on the edge of command buttons
|
| vbGrayText
| &H80000011
| Grayed (disabled) text
|
| vbButtonText
| &H80000012
| Text color on push buttons
|
| vbInactiveCaptionText
| &H80000013
| Color of text in an inactive caption
|
| vb3DHighlight
| &H80000014
| Highlight color for 3D display elements
|
| vb3DDKShadow
| &H80000015
| Darkest shadow color for 3D display elements
|
| vb3DLight
| &H80000016
| Second lightest of the 3D colors after vb3Dhighlight
|
| vb3DFace
| &H8000000F
| Color of text face
|
| vb3Dshadow
| &H80000010
| Color of text shadow
|
| vbInfoText
| &H80000017
| Color of text in tool tips
|
You can also specify colors as 4-byte integers directly, if you want to. The range for full RGB color is 0 to 16,777,215 (&HFFFFFF&).The high byte of a number in this range equals 0. The lower 3 bytes, from least to most significant byte, determine the amount of red, green, and blue. The red, green, and blue components are each represented by a number between 0 and 255 (&HFF). This means that you can specify a color as a hexadecimal number like this: &HBBGGRR&.
|