Results 1 to 5 of 5

Thread: Custom Cursor

  1. #1

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Custom Cursor

    Hi, I have this as my Custom Cursor:

    vb Code:
    1. Dim newCursor As Cursor = CreateCursor(Cursor1.PictureBox1.Image)
    2.             Me.Cursor = newCursor

    And then it appears for about 1 second then goes to the original cursor look!

    Thats just Error 1!

    In ths moving class that I made!

    vb Code:
    1. Public Class CustomCursor
    2.     Private Declare Sub SetCursorPos Lib "User32" (ByVal X As Integer, ByVal Y As Integer)
    3.     Private Const MOUSEEVENTF_LEFTDOWN = &H2
    4.     Private Const MOUSEEVENTF_LEFTUP = &H4
    5.     Private Const MOUSEEVENTF_RIGHYDOWN = &H6
    6.     Private Const MOUSEEVENTF_RIGHTUP = &H8
    7.     Private Declare Sub mouse_event Lib "user32" (ByVal dwFlags As Integer, ByVal dx As Integer, ByVal dy As Integer, ByVal cButtons As Integer, ByVal dwExtraInfo As Integer)
    8.  
    9.     Public Function MoveCursor(ByVal X As Integer, ByVal Y As Integer) As Single
    10.         Try
    11.             Dim IntX As Integer = CleanInteger(X, Form1.Location.X)
    12.             Dim IntY As Integer = CleanInteger(Y, Form1.Location.Y)
    13.             If Cursor.Position.X = IntX Then
    14.             Else
    15.                 If Cursor.Position.X < IntX Then
    16.                     SetCursorPos(Cursor.Position.X + 1, Cursor.Position.Y)
    17.                 ElseIf Cursor.Position.Y > IntX Then
    18.                     SetCursorPos(Cursor.Position.X - 1, Cursor.Position.Y)
    19.                 End If
    20.             End If
    21.             If Cursor.Position.Y = IntY Then
    22.             Else
    23.                 If Cursor.Position.Y < IntY Then
    24.                     SetCursorPos(Cursor.Position.X, Cursor.Position.Y + 1)
    25.                 ElseIf Cursor.Position.Y > IntY Then
    26.                     SetCursorPos(Cursor.Position.X, Cursor.Position.Y - 1)
    27.                 End If
    28.             End If
    29.             If Cursor.Position.X = IntX Then
    30.                 If Cursor.Position.Y = IntY Then
    31.                     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    32.                     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    33.                     Exit Function
    34.                 End If
    35.             End If
    36.             SpeedMove(X, Y)
    37.         Catch
    38.         End Try
    39.     End Function
    40.  
    41.     Public Function CleanInteger(ByVal Int As Integer, ByVal Target As Integer) As String
    42.         Dim i As Integer
    43.         i = Target + Int
    44.         Return i
    45.     End Function
    46.  
    47.     Public Function SpeedMove(ByVal X As Integer, ByVal Y As Integer) As Single
    48.         Try
    49.             Dim IntX As Integer = CleanInteger(X, Form1.Location.X)
    50.             Dim IntY As Integer = CleanInteger(Y, Form1.Location.Y)
    51.             If Cursor.Position.X = IntX Then
    52.             Else
    53.                 If Cursor.Position.X < IntX Then
    54.                     SetCursorPos(Cursor.Position.X + 1, Cursor.Position.Y)
    55.                 ElseIf Cursor.Position.Y > IntX Then
    56.                     SetCursorPos(Cursor.Position.X - 1, Cursor.Position.Y)
    57.                 End If
    58.             End If
    59.             If Cursor.Position.Y = IntY Then
    60.             Else
    61.                 If Cursor.Position.Y < IntY Then
    62.                     SetCursorPos(Cursor.Position.X, Cursor.Position.Y + 1)
    63.                 ElseIf Cursor.Position.Y > IntY Then
    64.                     SetCursorPos(Cursor.Position.X, Cursor.Position.Y - 1)
    65.                 End If
    66.             End If
    67.             If Cursor.Position.X = IntX Then
    68.                 If Cursor.Position.Y = IntY Then
    69.                     mouse_event(MOUSEEVENTF_LEFTDOWN, 0, 0, 0, 0)
    70.                     mouse_event(MOUSEEVENTF_LEFTUP, 0, 0, 0, 0)
    71.                     Exit Function
    72.                 End If
    73.             End If
    74.             MoveCursor(X, Y)
    75.         Catch
    76.         End Try
    77.     End Function
    78. End Class

    It gets errors on some bits of the code different bit of code the odd time, I have recorded some below also here is the error!

    Error:
    Code:
    An unhandled exception of type 'System.StackOverflowException' occurred in Microsoft.VisualBasic.dll
    Bits Error Occured:
    vb Code:
    1. Return i
    From the CleanInteger Function

    Hardly anything else but once I got it on

    vb Code:
    1. If Cursor.Position.X = IntX Then
    At the bottom of the SpeedMove Function

  2. #2
    Addicted Member
    Join Date
    Dec 2008
    Posts
    185

    Re: Custom Cursor

    Do you only want to change the appearance of the cursor?

    Maybe you need to make a base form that can be inherited. Heres an example that might be worth looking at:
    http://www.java2s.com/Code/VB/GUI/Ch...stomcursor.htm

  3. #3

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Custom Cursor

    Yes no only i need my mouse mover to make it move correctly + smoothly to my desination with

    vb Code:
    1. CustomCursor1.MoveCursor(20, 300)

  4. #4

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Custom Cursor

    *BUMP

    Desperate for Answer

  5. #5

    Thread Starter
    Addicted Member
    Join Date
    Nov 2009
    Posts
    146

    Re: Custom Cursor

    Yet as I see noone has given answer.

    ... -.- ...

    I thought people were meant to help not just look and think "oh i cba today ill ignore this guy".

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width