Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
C# Helper...
 
XML RSS Feed
Follow VBHelper on Twitter
 
 
MSDN Visual Basic Community
 
 
 
 
 
TitleDisplay system colors, their Hex values, and their RGB equivalents
Keywordssystem color, palette, RGB
CategoriesGraphics
 
This example displays its results in a FlexGrid control. For each system color, the program displays the color's name and color constant value. It uses GetSysColor to convert the color into an RGB value. Finally, it displays an empty cell with CellBackColor set to the color's RGB value so you can see a sample.
 
Private ColorNumbers As Collection
Private ColorNames As Collection

Private Sub Form_Load()
Dim r As Integer
Dim c As Integer
Dim new_wid As Single
Dim max_wid As Single
Dim txt As String
Dim rgb_color As Long

    Set ColorNumbers = New Collection
    Set ColorNames = New Collection

    ' Load the color names and numbers.
    ColorNumbers.Add COLOR_ACTIVEBORDER
    ColorNames.Add "COLOR_ACTIVEBORDER"
    ... code omitted ...

    ' Display the color values.
    flxColors.Rows = ColorNames.Count + 1
    flxColors.Cols = 4
    flxColors.FixedRows = 1
    flxColors.FixedCols = 0
    flxColors.TextMatrix(0, 0) = "Constant"
    flxColors.TextMatrix(0, 1) = "Hex Value"
    flxColors.TextMatrix(0, 2) = "RGB Value"
    flxColors.TextMatrix(0, 3) = "Sample"

    flxColors.Col = 3
    For r = 1 To ColorNames.Count
        ' Display the color name.
        flxColors.TextMatrix(r, 0) = ColorNames(r)

        ' Display the hex color number.
        flxColors.TextMatrix(r, 1) = Hex$(ColorNumbers(r))

        ' Display the hex RGB color value.
        rgb_color = GetSysColor(&HFFFFFF And _
            ColorNumbers(r))
        txt = Hex$(rgb_color)
        txt = String(6 - Len(txt), "0") & txt
        flxColors.TextMatrix(r, 2) = txt

        ' Display a sample.
        flxColors.Row = r
        flxColors.CellBackColor = rgb_color
    Next r

    ' Adjust the column sizes.
    For c = 0 To 3
        max_wid = 0
        For r = 0 To flxColors.Rows - 1
            new_wid = TextWidth(flxColors.TextMatrix(r, c))
            If max_wid < new_wid Then max_wid = new_wid
        Next r
        flxColors.ColWidth(c) = max_wid + 120
    Next c

    flxColors.ColAlignment(1) = flexAlignRightCenter
    flxColors.ColAlignment(2) = flexAlignRightCenter
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated