mattscotney Posted July 13, 2003 Posted July 13, 2003 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. Quote
Moderators Robby Posted July 13, 2003 Moderators Posted July 13, 2003 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) ? Quote Visit...Bassic Software
mattscotney Posted July 13, 2003 Author Posted July 13, 2003 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! Quote
*Experts* Volte Posted July 13, 2003 *Experts* Posted July 13, 2003 You can use your method with SetCursor; just pass myIcon.Handle into the API, rather than just myIcon. Quote
mattscotney Posted July 14, 2003 Author Posted July 14, 2003 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. Quote
*Gurus* divil Posted July 14, 2003 *Gurus* Posted July 14, 2003 You can't reliably change the mouse cursor for the whole screen. Quote MVP, Visual Developer - .NET Now you see why evil will always triumph - because good is dumb. My free .NET Windows Forms Controls and Articles
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.