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:
Asked
Active
Viewed 910 times
1

Martin Akbaev
- 37
- 4
-
2`Screen.FromPoint(Cursor.Position)` – CodingYoshi Dec 06 '19 at 20:38
-
`Cursor.Position` gives you the coordinates of the Mouse pointer in the current Screen. If you have more than one Display, the pointer coordinates in the secondary Screens are relative to the Primary Screen coordinates (so, the position can show negative values both in `X` and `Y`). See the notes here, in relation to the [Displays posiiton and VirtualScreen](https://stackoverflow.com/a/53026765/7444103) – Jimi Dec 06 '19 at 21:40
3 Answers
2
Here is how you get the bounds of all screens
// For each screen, add the screen properties to a list box.
foreach (var screen in System.Windows.Forms.Screen.AllScreens)
{
listBox1.Items.Add("Device Name: " + screen.DeviceName);
listBox1.Items.Add("Bounds: " +
screen.Bounds.ToString());
listBox1.Items.Add("Type: " +
screen.GetType().ToString());
listBox1.Items.Add("Working Area: " +
screen.WorkingArea.ToString());
listBox1.Items.Add("Primary Screen: " +
screen.Primary.ToString());
}
From the documentation https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.screen?view=netframework-4.8
as others have said to get the point in the screen you use Cursor.Position
.
https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.cursor.position?view=netframework-4.8
Basically you want to read all the documentation on the Screen object.

Hogan
- 69,564
- 10
- 76
- 117
1
To get the mouse screen coordinates:
public static Point GetMouseScreenPosition()
{
return Control.MousePosition;
}

Jackdaw
- 7,626
- 5
- 15
- 33
0
My problem was that I used a MouseMove event that doesn't work outside the form. Solved the problem using a timer.

Martin Akbaev
- 37
- 4