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 predefined system colors in Visual Basic .NET
DescriptionThis example shows how to display predefined system colors in Visual Basic .NET.
Keywordscolor, system color, SystemColors, drawing, graphics, VB.NET
CategoriesGraphics, VB.NET
 
The form's Paint event handler calls subroutine DrawColorSample for each defined SystemColors value. DrawColorSample fills a rectangle using a color and then displays the color's name.
 
Private Sub Form1_Paint(ByVal sender As Object, ByVal e As _
    System.Windows.Forms.PaintEventArgs) Handles _
    MyBase.Paint
    Dim y As Integer = 10
    DrawColorSample(e.Graphics, y, _
        SystemColors.ActiveBorder, "ActiveBorder")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ActiveCaption, "ActiveCaption")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ActiveCaptionText, "ActiveCaptionText")
    DrawColorSample(e.Graphics, y, _
        SystemColors.AppWorkspace, "AppWorkspace")
    DrawColorSample(e.Graphics, y, SystemColors.Control, _
        "Control")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ControlDark, "ControlDark")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ControlDarkDark, "ControlDarkDark")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ControlLight, "ControlLight")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ControlLightLight, "ControlLightLight")
    DrawColorSample(e.Graphics, y, _
        SystemColors.ControlText, "ControlText")
    DrawColorSample(e.Graphics, y, SystemColors.Desktop, _
        "Desktop")
    DrawColorSample(e.Graphics, y, SystemColors.GrayText, _
        "GrayText")
    DrawColorSample(e.Graphics, y, SystemColors.Highlight, _
        "Highlight")
    DrawColorSample(e.Graphics, y, _
        SystemColors.HighlightText, "HighlightText")
    DrawColorSample(e.Graphics, y, SystemColors.HotTrack, _
        "HotTrack")
    DrawColorSample(e.Graphics, y, _
        SystemColors.InactiveBorder, "InactiveBorder")
    DrawColorSample(e.Graphics, y, _
        SystemColors.InactiveCaption, "InactiveCaption")
    DrawColorSample(e.Graphics, y, _
        SystemColors.InactiveCaptionText, _
        "InactiveCaptionText")
    DrawColorSample(e.Graphics, y, SystemColors.Info, _
        "Info")
    DrawColorSample(e.Graphics, y, SystemColors.InfoText, _
        "InfoText")
    DrawColorSample(e.Graphics, y, SystemColors.Menu, _
        "Menu")
    DrawColorSample(e.Graphics, y, SystemColors.MenuText, _
        "MenuText")
    DrawColorSample(e.Graphics, y, SystemColors.ScrollBar, _
        "ScrollBar")
    DrawColorSample(e.Graphics, y, SystemColors.Window, _
        "Window")
    DrawColorSample(e.Graphics, y, _
        SystemColors.WindowFrame, "WindowFrame")
    DrawColorSample(e.Graphics, y, SystemColors.WindowText, _
        "WindowText")
End Sub

Private Sub DrawColorSample(ByVal gr As Graphics, ByRef y _
    As Integer, ByVal clr As Color, ByVal clr_name As _
    String)
    Dim br As New SolidBrush(clr)
    gr.FillRectangle(br, 10, y, 90, 10)
    br.Dispose()
    gr.DrawRectangle(Pens.Black, 10, y, 90, 10)
    gr.DrawString(clr_name, Me.Font, Brushes.Black, 110, y)
    y += 15
End Sub
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated