C# - Cursors.Hand.Handle does not identify cursor " Hand "

Asked

Viewed 51 times

1

I made a program to identify if the mouse cursor is Hand or not. I’m using an event that identifies the global cursor, so even outside the Form he is able to identify. The problem is that in the function:

private static bool Cursor()
    {
        var h = Cursors.Hand.Handle;

        CURSORINFO pci;
        pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
        GetCursorInfo(out pci);

        return pci.hCursor == h;
    }

When I test it on a button by placing the mouse on top of some Link or other thing that makes the cursor Hand, it does not identify! But if I change and put Cursors.Default.Handle it always identifies whether the cursor is Default or not.

What am I doing wrong ? How to identify if the cursor is Hand or not ?

  • To catch the current cursor is not Cursor.Current ?

1 answer

0

I think you’re getting the cursor wrong,

Try it this way

private static bool Cursor()
    {
        var h = Cursor.Current;

        CURSORINFO pci;
        pci.cbSize = Marshal.SizeOf(typeof(CURSORINFO));
        GetCursorInfo(out pci);

        return pci.hCursor == h;
    }

Browser other questions tagged

You are not signed in. Login or sign up in order to post.