相对于应用程序的光标位置

Mor*_*000 18 c# cursor winforms

我知道如何获得光标的位置:

 int X = Cursor.Position.X;
 int Y = Cursor.Position.Y;
Run Code Online (Sandbox Code Playgroud)

但这与屏幕有关.我如何获得相对于我的表格的坐标?

lc.*_*lc. 27

使用该Control.PointToClient方法.假设有this问题的表格:

var relativePoint = this.PointToClient(new Point(X, Y));
Run Code Online (Sandbox Code Playgroud)

或者干脆:

var relativePoint = this.PointToClient(Cursor.Position);
Run Code Online (Sandbox Code Playgroud)