Detect change in mouse cursor

Jim Webb 41 Reputation points
2021-04-05T22:42:57.51+00:00

Is it possible to detect the cursor change when the mouse moves over a control - for example when the cursor moves to the side of a window it changes from default to the Cursors.SizeWE (left-right arrow) cursor. I have tried using the CursorChanged event but it doesn't fire when the cursor changes. Is there something I am not setting in the event handler or do I need to use another event handler? The current code I am using is:

 Private Sub myForm_CursorChanged(sender As Object,
    e As EventArgs) _
    Handles Me.CursorChanged

 MyCur As Windows.Forms.Cursor = Me.Cursor

 End Sub

HotIndigo

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
2,889 questions
0 comments No comments
{count} votes

Accepted answer
  1. Castorix31 90,191 Reputation points
    2021-04-06T06:46:52.22+00:00

    A way is with SetWinEventHook
    with
    EVENT_OBJECT_NAMECHANGE
    and test if idObject = OBJID_CURSOR
    in the event hook function

    (tested on Windows 10 1909)

    0 comments No comments

0 additional answers

Sort by: Most helpful

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.