Search code examples
c#winformscursor-position

How to get cursor coordinates on desktop, not at the form using C#


All that I find works only when the cursor is inside the form. How to make it possible to find out the coordinates of the cursor anywhere on the screen? It works only if cursor is inside form:


Solution

  • To get the mouse screen coordinates:

    public static Point GetMouseScreenPosition()
    {
        return Control.MousePosition;
    }
    

    https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.mouseposition?view=netframework-4.8