Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

I would like to change the mouse cursor to my chosen cursor for the whole screen, not just within my application.

 

I know I have to use the setCursor API. I think my problem may be that I can't cast from types cursor to long.

 

Declare Function SetCursor Lib "user32" Alias "SetCursor" (ByVal hCursor As Long) As Long
Dim dropper = New Cursor("cursorDropper.ico")
Dim cursorChange As Long = SetCursor(dropper)

Any help will be greatly appreciated.

  • Moderators
Posted

you can use SetCapture ...

Private Declare Function SetCapture Lib "user32" (ByVal hwnd As Integer) As Integer

Then use the MouseDown event to keep the set cursor until you release the mouse..

   Private Sub Form1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles MyBase.MouseDown
       SetCapture(Me.Handle.ToInt32)
       Cursor.Current = New Cursor(Application.StartupPath & "\cursorDropper.cur")
   End Sub

Also, shouldn't you be using a cursor (cur) not an icon (ico) ?

Visit...Bassic Software
Posted

Thanks Robby,

 

Your solution works, however it does not match my specs as the mouse button has to be physically held down.

 

Is there another way using a button click event to change the cursor to cursorDropper and a click anywhere on the screen to change the cursor back?

 

I am now using a cursor rather than an icon, not sure how I managed that one!

Posted

Hi Volte,

 

I tried passing the handle to the API but the code still does not work. I have pasted the revised version below. Please advise what I am doing wrong?

Declare Function SetCursor Lib "user32" Alias "SetCursor" (ByVal hCursor As Long) As Long
Dim dropper = New Cursor("cursorDropper.ico")
Dim cursorChange As Long = SetCursor(dropper.handle)

The above version still gives a cast error.

 

I also tried:

Dim cursorChange As Long = SetCursor(dropper.handle.toint32)

This one solved the cast error, but the mouse cursor did not change.

 

Thanks again.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...