Home
Search
 
What's New
Index
Books
Links
Q & A
Newsletter
Banners
 
Feedback
Tip Jar
 
XML RSS Feed
 
 
 
 
 
 
 
 
TitleDisplay the SystemColors in Visual Basic .NET
DescriptionThis example shows how to display the SystemColors in Visual Basic .NET. It calls a subroutine to display the name of each value in SystemColors and draw a sample.
KeywordsSystemColors
CategoriesGraphics, VB.NET
 
The form's Paint event handler calls subroutine DrawSample for each value in SystemColors.

DrawSample draws the name of the color and fills a rectangle with a sample of that color. It then updates the X and Y position where it will draw the next color.

 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim x As Integer
    Dim y As Integer
    DrawSample(e.Graphics, x, y, SystemColors.ActiveBorder)
    DrawSample(e.Graphics, x, y, SystemColors.ActiveCaption)
    DrawSample(e.Graphics, x, y, _
        SystemColors.ActiveCaptionText)
    DrawSample(e.Graphics, x, y, SystemColors.AppWorkspace)
    DrawSample(e.Graphics, x, y, SystemColors.Control)
    DrawSample(e.Graphics, x, y, SystemColors.ControlDark)
    DrawSample(e.Graphics, x, y, _
        SystemColors.ControlDarkDark)
    DrawSample(e.Graphics, x, y, SystemColors.ControlLight)
    DrawSample(e.Graphics, x, y, _
        SystemColors.ControlLightLight)
    DrawSample(e.Graphics, x, y, SystemColors.ControlText)
    DrawSample(e.Graphics, x, y, SystemColors.Desktop)
    DrawSample(e.Graphics, x, y, SystemColors.GrayText)
    DrawSample(e.Graphics, x, y, SystemColors.Highlight)
    DrawSample(e.Graphics, x, y, SystemColors.HighlightText)
    DrawSample(e.Graphics, x, y, SystemColors.HotTrack)
    DrawSample(e.Graphics, x, y, _
        SystemColors.InactiveBorder)
    DrawSample(e.Graphics, x, y, _
        SystemColors.InactiveCaption)
    DrawSample(e.Graphics, x, y, _
        SystemColors.InactiveCaptionText)
    DrawSample(e.Graphics, x, y, SystemColors.Info)
    DrawSample(e.Graphics, x, y, SystemColors.InfoText)
    DrawSample(e.Graphics, x, y, SystemColors.Menu)
    DrawSample(e.Graphics, x, y, SystemColors.MenuText)
    DrawSample(e.Graphics, x, y, SystemColors.ScrollBar)
    DrawSample(e.Graphics, x, y, SystemColors.Window)
    DrawSample(e.Graphics, x, y, SystemColors.WindowFrame)
    DrawSample(e.Graphics, x, y, SystemColors.WindowText)
End Sub

Private Sub DrawSample(ByVal gr As Graphics, ByRef x As _
    Integer, ByRef y As Integer, ByVal clr As Color)
    gr.DrawString(clr.Name, Me.Font, Brushes.Black, x, y)
    Dim the_brush As New SolidBrush(clr)
    gr.FillRectangle(the_brush, x, y + 15, 100, 20)
    gr.DrawRectangle(Pens.Black, x, y + 15, 100, 20)

    y += 40
    If y + 40 > Me.ClientRectangle.Height Then
        x += 150
        y = 0
    End If
End Sub
 
 
Copyright © 1997-2003 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated