rosu alin
rosu alin

Reputation: 5830

I cannot access Position of the cursor (move mouse programatically)

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.

Upvotes: 1

Views: 4256

Answers (3)

rosu alin
rosu alin

Reputation: 5830

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.

Upvotes: 0

user2596213
user2596213

Reputation:

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".

Upvotes: 8

Aghilas Yakoub
Aghilas Yakoub

Reputation: 28970

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

Upvotes: 1

Related Questions