Color Constants / Color Forms / Controls / Transparency VB6
From Free Knowledge Base- The DUCK Project: information for everyone
(Redirected from Color Constants in VB6)
Contents
VB / VBA Color Constants
Table 1
VBA Constant | SystemColors | Hex Value | Long Value | Description |
vb3DDKShadow | ControlDarkDark | &H80000015 | -2147483627 | Darkest shadow color for 3-D display elements |
vb3DHighlight | ControlLightLight | &H80000014 | -2147483628 | Highlight color for 3-D display elements |
vb3DLight | ControlLight | &H80000016 | -2147483626 | Second lightest 3-D color after vb3DHighlight |
vb3DShadow | ControlDark | &H80000010 | -2147483632 | Lightest shadow color for 3-D display elements |
vbActiveBorder | ActiveBorder | &H8000000A | -2147483638 | Border color of active window |
vbActiveTitleBar | ActiveCaption | &H80000002 | -2147483646 | Color of the title bar for the active window |
vbApplicationWorkspace | AppWorkspace | &H8000000C | -2147483636 | Background color of multiple document interface (MDI) applications |
vbButtonFace (vb3DFace) | Control | &H8000000F | -2147483633 | Color of shading on the face of command buttons |
vbButtonShadow (vb3DShadow) | ControlDark | &H80000010 | -2147483632 | Color of shading on the edge of command buttons |
vbButtonText | ControlText | &H80000012 | -2147483630 | Text color on push buttons |
vbDesktop | Desktop | &H80000001 | -2147483647 | Desktop color |
vbGrayText | GrayText | &H80000011 | -2147483631 | Grayed (disabled) text |
vbHighlight | Highlight | &H8000000D | -2147483635 | Background color of items selected in a control |
vbHighlightText | HighlightText | &H8000000E | -2147483634 | Text color of items selected in a control |
vbInactiveBorder | InactiveBorder | &H8000000B | -2147483637 | Border color of inactive window |
vbInactiveCaptionText | InactiveCaptionText | &H80000013 | -2147483629 | Color of text in an inactive caption |
vbInactiveTitleBar | InactiveCaption | &H80000003 | -2147483645 | Color of the title bar for the inactive window |
vbInfoBackground(vbMsgBoxText) | Info | &H80000018 | -2147483624 | Background color of ToolTips |
vbInfoText(vbMsgBox) | InfoText | &H80000017 | -2147483625 | Color of text in ToolTips |
vbMenuBar | Menu | &H80000004 | -2147483644 | Menu background color |
vbMenuText | MenuText | &H80000007 | -2147483641 | Color of text on menus |
vbScrollBars | ScrollBar | &H80000000 | -2147483648 | Scrollbar color |
vbTitleBarText | ActiveCaptionText | &H80000009 | -2147483639 | Color of text in caption, size box, and scroll arrow |
vbWindowBackground | Window | &H80000005 | -2147483643 | Window background color |
vbWindowFrame | WindowFrame | &H80000006 | -2147483642 | Window frame color |
vbWindowText | WindowText | &H80000008 | -2147483640 | Color of text in windows |
Table 2
System Colour Name | Hex Value | VB Constant |
Menu Text | &H80000007& | vbMenuText |
Scroll Bars | &H80000000& | vbScrollBars |
Window Background | &H80000005& | vbWindowBackground |
Window Frame | &H80000006& | vbWindowFrame |
Window Text | &H80000008& | vbWindowText |
Active Border | &H8000000A& | vbActiveBorder |
Active Title Bar | &H80000002& | vbActiveTitleBar |
Active Title Bar Text | &H80000009& | vbTitleBarText |
Application Workspace | &H8000000C& | vbApplicationWorkspace |
Button Face | &H8000000F& | vbButtonFace |
Button Highlight | &H80000014& | vb3DHighlight |
Button Shadow | &H80000010& | vb3DDKShadow |
Button Text | &H80000012& | vbButtonText |
Desktop | &H80000001& | vbDesktop |
Disabled Text | &H80000011& | vbGrayText |
Highlight | &H8000000D& | vbHighlight |
Highlighted Text | &H8000000E& | vbHighlightText |
Inactive Border | &H8000000B& | vbInactiveBorder |
Inactive Title Bar | &H80000003& | vbInactiveTitleBar |
Inactive Title Bar Text | &H80000013& | vbInactiveCaptionText |
Menu Bar | &H80000004& | vbMenuBar |
Table 3
The eight members of the VBA Color Constants class:
- vbBlack
- vbWhite
- vbRed
- vbGreen
- vbBlue
- vbYellow
- vbMagenta
- vbCyan
Examples
Example 1:
txtCon(cnt).BackColor = vbHighlightText
Example 2: This is the same as "Button Highlight"
txtCon(cnt).BackColor = vbHighlightText
Setting Form and Control Colors
- Blue : Me.BackColor = RGB(0, 0, 255)
Me.BackColor = RGB(0, 0, 255)
- Green: Me.BackColor = RGB(0, 255, 0)
Me.BackColor = RGB(0, 255, 0)
- Red: Me.BackColor = RGB(255, 0, 0)
Me.BackColor = RGB(255, 0, 0)
All Possible Ways
1. In HEX, BLUE is first, Green, then Red, the reverse of RGB (actually BGR) is the default VB method
cmd(0).BackColor = &HFF& ' Red / &H0000FF& cmd(1).BackColor = &HFF00& ' Green / &H00FF00& cmd(2).BackColor = &HFF0000 ' Blue / &HFF0000&
2. Decimal RGB value
cmd(0).BackColor = RGB(255, 0, 0) cmd(1).BackColor = RGB(0, 255, 0) cmd(2).BackColor = RGB(0, 0, 255)
3. Using VB Color Constants
cmd(0).BackColor = vbRed cmd(1).BackColor = vbGreen cmd(2).BackColor = vbBlue
Convert RGB Hex (like used in HTML) to VB Hex
Code Sample:
Public Function h2v(wHex As String) As Long Dim strTmp As String wHex = Trim("" & wHex) If Len(wHex) = 7 Then If Left(wHex, 1) = "#" Then wHex = Right(wHex, 6) End If If Len(wHex) = 6 Then strTmp = "&H" & Right(wHex, 2) & Mid(wHex, 3, 2) & Left(wHex, 2) & "&" Else strTmp = "&H000000&" End If h2v = Val(strTmp) Debug.Print h2v End Function
Transparency
Entire Form and all controls
Option Explicit Private Const GWL_EXSTYLE = (-20) Private Const WS_EX_LAYERED = &H80000 Private Const LWA_ALPHA = &H2 Private Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long) As Long Private Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hWnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Private Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hWnd As Long, ByVal crKey As Long, ByVal bAlpha As Byte, ByVal dwFlags As Long) As Long Private Sub Form_Load() TranslucentForm Me, 255 'Make form 0% translucent End Sub Private Sub Slider1_Scroll() TranslucentForm Me, Slider1.Value End Sub Public Function TranslucentForm(frm As Form, TranslucenceLevel As Byte) As Boolean SetWindowLong frm.hWnd, GWL_EXSTYLE, WS_EX_LAYERED SetLayeredWindowAttributes frm.hWnd, 0, TranslucenceLevel, LWA_ALPHA TranslucentForm = Err.LastDllError = 0 End Function
By Color + Hollow Form
Option Explicit Public Const LWA_COLORKEY = 1 Public Const LWA_ALPHA = 2 Public Const LWA_BOTH = 3 Public Const WS_EX_LAYERED = &H80000 Public Const GWL_EXSTYLE = -20 Public Declare Function SetLayeredWindowAttributes Lib "user32" (ByVal hwnd As Long, ByVal bXColor As Long, ByVal x As Byte, ByVal a lpha As Long) As Boolean Public Declare Function SetWindowLong Lib "user32" Alias "SetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long, ByVal dwNewLong As Long) As Long Public Declare Function GetWindowLong Lib "user32" Alias "GetWindowLongA" (ByVal hwnd As Long, ByVal nIndex As Long) As Long
Public g_nTransparency As Integer Public bXColor As Long Public flag As Byte Option Explicit Private Sub cmdExit_Click() Unload Me End Sub Private Sub Form_Load() initFormControls initTransParency End Sub Private Sub initFormControls() Me.Width = Screen.Width: Me.Height = Screen.Height: Me.Top = 0: Me.Left = 0 cmdExit.Left = Screen.Width - 800: cmdExit.Top = 200 End Sub Private Sub initTransParency() bXColor = RGB(1, 2, 3) Me.BackColor = bXColor g_nTransparency = 150 flag = 0 Or LWA_COLORKEY SetTranslucent Me.hwnd, bXColor, g_nTransparency, flag End Sub
Option Explicit Sub SetTranslucent(ThehWnd As Long, bXColor As Long, nTrans As Integer, flag As Byte) Dim attrib As Long On Error GoTo ErrorRtn attrib = GetWindowLong(ThehWnd, GWL_EXSTYLE) SetWindowLong ThehWnd, GWL_EXSTYLE, attrib Or WS_EX_LAYERED SetLayeredWindowAttributes ThehWnd, bXColor, nTrans, flag Exit Sub ErrorRtn: MsgBox Err.Description & " Source : " & Err.Source End Sub