I cannot access Position of the cursor (move mouse

2020-04-27 04:30发布

this is my code:

    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);
    }

This is what my console says:

 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

Now, I'm a beginner in c#, i'm more used to java and android. A friend told me it has something to do with instances. but i do not know exactly what to do.

3条回答
Emotional °昔
2楼-- · 2020-04-27 04:42

You probably found your answer already or figured out a workaround, but since I had this same issue I thought I'd post what I discovered.

The error popped up for me when I added a reference to System.Windows.Forms.DataVisualization.Charting. It seems that the way the cursor works with that reference is different from usual, and overrides the typical Cursor.Position.

In my case, it was as simple as replacing "Cursor.Position" with "MousePosition".

查看更多
甜甜的少女心
3楼-- · 2020-04-27 04:43

I suggest you this code

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

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

查看更多
小情绪 Triste *
4楼-- · 2020-04-27 04:49

I found out what the issue was, Kinect does not send the parameters of the screen from 0 to display width, and it also has a - in the left part of the body, and + in the right, so I had to make a function to calculate the corect point to move the mouse to.

查看更多
登录 后发表回答