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 icons in Visual Basic .NET
DescriptionThis example shows how to display predefined system icons in Visual Basic .NET.
Keywordsicon, system icon, SystemIcons, drawing, graphics, VB.NET
CategoriesGraphics, VB.NET
 
The form's Paint event handler calls subroutine DrawIconSample for each defined SystemIcons value. DrawIconSample draws an icon and then displays the icon'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
    DrawIconSample(e.Graphics, y, SystemIcons.Application, _
        "Application")
    DrawIconSample(e.Graphics, y, SystemIcons.Asterisk, _
        "Asterisk")
    DrawIconSample(e.Graphics, y, SystemIcons.Error, _
        "Error")
    DrawIconSample(e.Graphics, y, SystemIcons.Exclamation, _
        "Exclamation")
    DrawIconSample(e.Graphics, y, SystemIcons.Hand, "Hand")
    DrawIconSample(e.Graphics, y, SystemIcons.Information, _
        "Information")
    DrawIconSample(e.Graphics, y, SystemIcons.Question, _
        "Question")
    DrawIconSample(e.Graphics, y, SystemIcons.Warning, _
        "Warning")
    DrawIconSample(e.Graphics, y, SystemIcons.WinLogo, _
        "WinLogo")
End Sub

Private Sub DrawIconSample(ByVal gr As Graphics, ByRef y As _
    Integer, ByVal ico As Icon, ByVal ico_name As String)
    gr.DrawIconUnstretched(ico, New Rectangle(10, y, _
        ico.Width, ico.Height))
    Dim text_y As Integer = y + (ico.Height - _
        CInt(gr.MeasureString(ico_name, Me.Font).Height)) \ _
        2
    gr.DrawString(ico_name, Me.Font, Brushes.Black, _
        ico.Width + 20, text_y)
    y += ico.Height + 5
End Sub
 
Note that on my system at least some of the icons are duplicates. For example, Asterisk looks like the Information balloon, Hand looks like the Error X, and Warning looks like the Exclamation triangle (that one makes at least some sense).
 
 
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.
  Updated