Click here to Skip to main content
15,894,124 members
Please Sign up or sign in to vote.
2.00/5 (1 vote)
See more:
I want to change the cursor not only in my form. And when i finish i want to change it back as it was.
Any help?!

Thanks in advance :)

additonal content copied from comment below
I tried this code:
VB
Private Const OCR_NORMAL As UInteger = 32512
<DllImport("user32.dll")> _
Private Shared Function LoadCursorFromFile _
                        (ByVal lpFileName As String) _
                        As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function SetSystemCursor _
                        (ByVal hCursor As IntPtr, _
                        ByVal id As Integer) _
                        As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function LoadCursor(ByVal hInstance As IntPtr, _
                                  ByVal id As UInteger) _
                                  As IntPtr
End Function
Private Sub frm_Load(ByVal sender As System.Object, _
                               ByVal e As System.EventArgs) _
                               Handles MyBase.Load
   Dim cursor As IntPtr = LoadCursorFromFile("C:\cursor.cur")
   SetSystemCursor(cursor, OCR_NORMAL)
End Sub
Private Sub btn_Click(ByVal sender As System.Object, _
                      ByVal e As System.EventArgs) _
                      Handles btn.Click
    SetSystemCursor(LoadCursor(IntPtr.Zero, OCR_NORMAL), OCR_NORMAL)
End Sub

---------------------------------------------------------------------------------
This code worked for changing the cursor, but it didnt return it back :(
Posted
Updated 16-Oct-13 2:11am
v2
Comments
Nelek 16-Oct-13 7:30am    
Hadi Ayash 16-Oct-13 8:05am    
I tried this code:
Private Const OCR_NORMAL As UInteger = 32512
<DllImport("user32.dll")> _
Private Shared Function LoadCursorFromFile _
(ByVal lpFileName As String) _
As IntPtr
End Function
<DllImport("user32.dll")> _
Private Shared Function SetSystemCursor _
(ByVal hCursor As IntPtr, _
ByVal id As Integer) _
As Boolean
End Function
<DllImport("user32.dll")> _
Public Shared Function LoadCursor(ByVal hInstance As IntPtr, _
ByVal id As UInteger) _
As IntPtr
End Function
Private Sub frm_Load(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles MyBase.Load
Dim cursor As IntPtr = LoadCursorFromFile("C:\cursor.cur")
SetSystemCursor(cursor, OCR_NORMAL)
End Sub
Private Sub btn_Click(ByVal sender As System.Object, _
ByVal e As System.EventArgs) _
Handles btn.Click
SetSystemCursor(LoadCursor(IntPtr.Zero, OCR_NORMAL), OCR_NORMAL)
End Sub
----------------------------------------------------------------------------------------------
This code worked for changing the cursor, but it didnt return it back :(
Sergey Alexandrovich Kryukov 16-Oct-13 13:44pm    
What does it mean: "I want to change the cursor not only in my form"? Another form of the same application, or something else? If the same, what's the difference which form is that? If not, why abusing other applications so much?
—SA

1 solution

Before you set your custom Cursor, you have to write the current cursor into some variable of your application (isn't there a function like GetSystemCursor?), and when your application stops (e.g. in the FormClosing event), you set it back to the original value which you stored above.
 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900