What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleDisplay samples of the colors defined in VBRUN.SystemColorConstants
DescriptionThis example shows how to display samples of the colors defined in VBRUN.SystemColorConstants in Visual Basic 6.
Keywordscolor, system colors, VBRUN, SystemColorConstants
CategoriesGraphics, Software Engineering
The VBRUN library's SystemColorConstants enumeration defines constants that represent standard system colors. You can use those colors to make program elements match the system elements. This program displays samples of those colors.

When it starts, the program fills the m_ColorName and m_ColorValues collections with the samples' names and numeric values. It then loops through the collections, displaying color names in Labels and samples in PictureBoxes.

Private m_ColorNames As Collection
Private m_ColorValues As Collection

Private Sub AddColor(ByVal color_name As String, ByVal _
    color_value As OLE_COLOR)
    m_ColorNames.Add color_name
    m_ColorValues.Add color_value
End Sub

Private Sub Form_Load()
Dim gap As Single
Dim hgt As Single
Dim Dx As Single
Dim Dy As Single
Dim x As Single
Dim y As Single
Dim i As Integer

    Set m_ColorNames = New Collection
    Set m_ColorValues = New Collection

    AddColor "vb3DDKShadow", vb3DDKShadow
    AddColor "vb3DFace", vb3DFace
    AddColor "vb3DHighlight", vb3DHighlight
    AddColor "vb3DLight", vb3DLight
    AddColor "vb3DShadow", vb3DShadow
    AddColor "vbActiveBorder", vbActiveBorder
    AddColor "vbActiveTitleBar", vbActiveTitleBar
    AddColor "vbActiveTitleBarText", vbActiveTitleBarText
    AddColor "vbApplicationWorkspace", _
    AddColor "vbButtonFace", vbButtonFace
    AddColor "vbButtonShadow", vbButtonShadow
    AddColor "vbButtonText", vbButtonText
    AddColor "vbDesktop", vbDesktop
    AddColor "vbGrayText", vbGrayText
    AddColor "vbHighlight", vbHighlight
    AddColor "vbHighlightText", vbHighlightText
    AddColor "vbInactiveBorder", vbInactiveBorder
    AddColor "vbInactiveCaptionText", vbInactiveCaptionText
    AddColor "vbInactiveTitleBar", vbInactiveTitleBar
    AddColor "vbInactiveTitleBarText", _
    AddColor "vbInfoBackground", vbInfoBackground
    AddColor "vbInfoText", vbInfoText
    AddColor "vbMenuBar", vbMenuBar
    AddColor "vbMenuText", vbMenuText
    AddColor "vbScrollBars", vbScrollBars
    AddColor "vbTitleBarText", vbTitleBarText
    AddColor "vbWindowBackground", vbWindowBackground
    AddColor "vbWindowFrame", vbWindowFrame
    AddColor "vbWindowText", vbWindowText

    gap = lblName(0).Top - picSample(0).Top
    hgt = gap + lblName(0).Height + 120
    Dx = picSample(0).Width + 120
    Dy = gap + lblName(0).Height + 120
    x = 120
    y = 120
    For i = 1 To m_ColorNames.Count
        Load picSample(i)
        picSample(i).Move x, y
        picSample(i).BackColor = m_ColorValues(i)
        picSample(i).Visible = True

        Load lblName(i)
        lblName(i).Move x, y + gap
        lblName(i).Caption = m_ColorNames(i)
        lblName(i).Visible = True

        y = y + Dy
        If y + hgt > ScaleHeight Then
            y = 120
            x = x + Dx
        End If
    Next i
End Sub
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.