I know how to track the cursor with Form1.MousePosition but it gives me cursor position relative to the screen, not actual form. Is there a way to track it relative to the Form? Even when I move it (its 1000*1000)! I really appreciate any help you can provide.
Asked
Active
Viewed 56 times
1
-
1You probably want to look at [Control.PointToClient](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.pointtoclient) and its friend [PointToScreen](https://learn.microsoft.com/en-us/dotnet/api/system.windows.forms.control.pointtoscreen) – Flydog57 Jul 01 '22 at 22:00
1 Answers
1
You could register on the MouseMove event of the Form
.
this.MouseMove += new System.Windows.Forms.MouseEventHandler(this.Form1_MouseMove);
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
// e.Location.X;
// e.Location.Y;
}

Jeroen van Langen
- 21,446
- 3
- 42
- 57
-
1This supposes the Form doesn't contain any Control that can receive mouse input. You could suggest to use a Timer or a class that implements `IMessageFilter` (it could be the Form itself) -- A generic class can be registered (`Application.AddMessageFilter()`) in Program.cs, so mouse activity can be tracked application-wide. – Jimi Jul 01 '22 at 22:10