我无法访问光标的位置(以编程方式移动鼠标)

这是我的代码:

private void MoveCursor(int x, int y) { // Set the Current cursor, move the cursor's Position, // and set its clipping rectangle to the form. System.Windows.Forms.Cursor cursorMouse = new System.Windows.Forms.Cursor(System.Windows.Forms.Cursor.Current.Handle); cursorMouse.Position = new System.Drawing.Point(x, y); System.Windows.Forms.Cursor.Clip = new System.Drawing.Rectangle(cursorMouse.Position, cursorMouse.Size); } 

这就是我的控制台所说的:

  Error 11 Member 'System.Windows.Forms.Cursor.Position.get' cannot be accessed with an instance reference; qualify it with a type name instead F:\Win8\Kinect\InterfaceController\celmaibun\KinectToolbox\KinectToolbox\GesturesViewer\MainWindow.xaml.cs 1314 13 NkGesturesViewer Error 12 Member 'System.Windows.Forms.Cursor.Position.get' cannot be accessed with an instance reference; qualify it with a type name instead F:\Win8\Kinect\InterfaceController\celmaibun\KinectToolbox\KinectToolbox\GesturesViewer\MainWindow.xaml.cs 1315 77 NkGesturesViewer 

现在,我是c#的初学者,我更习惯于java和android。 一位朋友告诉我这与实例有关。 但我不知道该怎么做。

您可能已经找到了答案或找到了解决方法,但由于我遇到了同样的问题,我想我会发布我发现的内容。

当我添加对System.Windows.Forms.DataVisualization.Charting的引用时,弹出的错误。 似乎光标与该引用一起工作的方式与通常不同,并且覆盖了典型的Cursor.Position。

在我的例子中,它就像用“MousePosition”替换“Cursor.Position”一样简单。

我建议你这个代码

 var pc = new PointConverter(); var pt = new Point(); pt = (Point)pc.ConvertFromString(string.Format("{0}, {1}",x,y)); cursorMouse.Position = pt; 

链接: http : //msdn.microsoft.com/en-us/library/system.drawing.pointconverter.aspx

我发现问题是什么,Kinect没有将屏幕的参数从0发送到显示宽度,并且它还有一个 – 在身体的左侧部分,+在右侧,所以我不得不做一个function计算要移动鼠标的核心点。