What's New
Q & A
Tip Jar
C# Helper...
Follow VBHelper on Twitter
MSDN Visual Basic Community
TitleDisplay the standard cursors in VB .NET
DescriptionThis example shows how to display the standard cursors in VB .NET. The program uses each cursor's ToString method to get its name and its Draw method to draw the cursor on a Bitmap.
Keywordsicon, VB .NET
CategoriesVB.NET, Graphics
The Cursors class provides a bunch of standard icons: Wait, Default, UpArrow, etc. This program displays them so you can see what they look like.

The main program calls subroutine AddCursor for each of the standard cursors.

AddCursor calls the cursor's ToString method and parses the result to get the cursor's name. It creates a new Label control and displays the name.

Next the routine makes a Bitmap and associated Graphics object. It calls the cursor's Draw method to draw the cursor on the Bitmap. It then makes a new PictureBox and displays the Bitmap in it.

While it does all this, the program keeps track of the biggest X and Y coordinate it uses. When it is finished, the Form1_Load event handler makes the form big enough to show all of the cursors.

Private xmax As Integer = 0
Private ymax As Integer = 0

Private Sub Form1_Load(ByVal sender As System.Object, ByVal _
    e As System.EventArgs) Handles MyBase.Load

    Me.ClientSize = New Size(xmax, ymax)
End Sub

Private Sub AddCursor(ByVal the_cursor As Cursor)
    Const LBL_WID As Integer = 80
    Const PIC_WID As Integer = 50
    Static x As Integer = 0
    Static y As Integer = -40
    Static i As Integer = 0
    i += 1
    If i Mod 4 = 1 Then
        x = 0
        y += PIC_WID
    End If

    Dim txt As String = the_cursor.ToString
    txt = txt.Replace("[Cursor: ", "")
    txt = txt.Replace("]", "")

    Dim lbl As New Label
    lbl.Location = New System.Drawing.Point(x, y)
    lbl.AutoSize = True
    lbl.Text = txt
    x += LBL_WID

    Dim bm As New Bitmap(32, 32)
    Dim gr As Graphics = Graphics.FromImage(bm)
    the_cursor.Draw(gr, New Rectangle(0, 0, 32, 32))

    Dim pic As New PictureBox
    pic.Location = New System.Drawing.Point(x, y)
    pic.BorderStyle = BorderStyle.Fixed3D
    pic.ClientSize = New Size(32, 32)
    pic.Image = bm
    x += PIC_WID

    If xmax < x Then xmax = x
    If ymax < y + PIC_WID Then ymax = y + PIC_WID
End Sub
Copyright © 1997-2010 Rocky Mountain Computer Consulting, Inc.   All rights reserved.