Click here to Skip to main content
14,021,911 members
Click here to Skip to main content
Add your own
alternative version


16 bookmarked
Posted 15 Jul 2008
Licenced CPOL

Changing the Systems Cursor in VB.NET

, 15 Jul 2008
Rate this:
Please Sign up or sign in to vote.
Replace a cursor system-wide and restore it to the original cursor.


I have always come to this site for help, so it's time for me to give back. This is my first post here, so be gentle :P

The point of this article is to show you how to replace a cursor system-wide, and specifically, how to restore it to the original cursor once you're ready to do so.


Changing a system cursor was cake for me, but a problem came about when I wanted to restore that system cursor back to the original cursor. Many suggested to use the LoadCursor or LoadImage API to restore the cursor, but it seemed (for me at least) that neither API worked in VB.NET. So, on my own, I came up with the following solution.

Using the code

I'm not sure if this is the best way to do it, but it seems to work fairly well. The main code from the sample project is as follows:

'Variable to save current cursor
Dim SavedCursor As Icon

Private Sub Button1_Click(ByVal sender As System.Object, _
            ByVal e As System.EventArgs) Handles Button1.Click
    'Save cursor
    SavedCursor = Icon.FromHandle(Cursors.Arrow.CopyHandle)

    'Change arrow cursor to mine
    Dim NewCursor As IntPtr = _
        LoadCursorFromFile(Application.StartupPath & "\MyCross.cur")

    If NewCursor = IntPtr.Zero Then
        'Error loading cursor from file
        Debug.WriteLine("Error loading cursor from file.")
    End If

    'Set the system cursor
    If SetSystemCursor(NewCursor, IDC_ARROW) = 0 Then
        'Error setting system cursor
        Debug.WriteLine("Error setting system cursor.")
    End If

    'Disable/enable buttons
    Button1.Enabled = False
    Button2.Enabled = True
End Sub

Private Sub Button2_Click(ByVal sender As System.Object, _
        ByVal e As System.EventArgs) Handles Button2.Click
    'Get old cursor
    Dim OldCursor As IntPtr = SavedCursor.Handle

    'Set the system cursor
    SetSystemCursor(OldCursor, IDC_ARROW)

    'Disable/enable buttons
    Button1.Enabled = True
    Button2.Enabled = False
End Sub

Points of Interest

This sample was written and tested in Visual Studio 2008 using .NET Framework 3.5. Any feedback would be great (especially if anyone has any improvements).


  • Release 1 (July 15th, 2008).


This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

Dan Dombrowski
Software Developer 12:34 MicroTechnologies, Inc.
United States United States
No Biography provided

You may also be interested in...


Comments and Discussions

GeneralMy vote of 5 Pin
Froopy3-Apr-17 11:08
memberFroopy3-Apr-17 11:08 
Questionthanks very mush Pin
Member 1132300619-Dec-14 2:32
memberMember 1132300619-Dec-14 2:32 
GeneralThank you! Thank you! Thank you! Pin
Casey Sheridan31-Oct-13 16:15
professionalCasey Sheridan31-Oct-13 16:15 
QuestionHow to use my own cursor? Pin
NicolaasP10-Nov-08 23:15
memberNicolaasP10-Nov-08 23:15 
AnswerRe: How to use my own cursor? Pin
Dan Dombrowski16-Nov-09 8:05
memberDan Dombrowski16-Nov-09 8:05 
AnswerWait Cursor Class in VB.NET Pin
Dougie the P22-Jul-08 8:43
professionalDougie the P22-Jul-08 8:43 
GeneralRe: Wait Cursor Class in VB.NET Pin
Dan Dombrowski16-Nov-09 8:06
memberDan Dombrowski16-Nov-09 8:06 
GeneralRe: Wait Cursor Class in VB.NET Pin
Dougie the P16-Nov-09 8:16
professionalDougie the P16-Nov-09 8:16 
GeneralRe: Wait Cursor Class in VB.NET Pin
Dan Dombrowski20-Nov-09 6:56
memberDan Dombrowski20-Nov-09 6:56 
GeneralRe: Wait Cursor Class in VB.NET Pin
bhogsett6-Jan-10 10:25
memberbhogsett6-Jan-10 10:25 
GeneralCoding style, bravo! Pin
Bkins15-Jul-08 15:18
memberBkins15-Jul-08 15:18 
GeneralRe: Coding style, bravo! Pin
Dan Dombrowski16-Nov-09 8:02
memberDan Dombrowski16-Nov-09 8:02 
GeneralRe: Coding style, bravo! Pin
hokhok88810-Feb-14 4:42
memberhokhok88810-Feb-14 4:42 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Cookies | Terms of Use | Mobile
Web01 | 2.8.190417.4 | Last Updated 15 Jul 2008
Article Copyright 2008 by Dan Dombrowski
Everything else Copyright © CodeProject, 1999-2019
Layout: fixed | fluid