我正在做一个项目来控制鼠标,在下面的代码中,我有点迷路。this.Cursor not working properly?
我需要声明的对象命名空间:
using System.Windows;
using System.Windows.Forms;
using System.Drawing;
,并在这里代码:
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
Cursor.Clip = new Rectangle(this.Location, this.Size);
它告诉我,光标不会在上下文中存在,但只有在this.Cursor
。同样适用于this.Loc
和this.Size
。有人知道为什么我错过了一个命名空间吗?
编辑:确切的代码:
public class MouseMove
{
[DllImport("user32.dll")] //TODO add block feature on screens that need it
private static extern bool BlockInput(bool block);
public static void Main()
{
this.Cursor = new Cursor(Cursor.Current.Handle);
Cursor.Position = new Point(Cursor.Position.X, Cursor.Position.Y);
Cursor.Clip = new Rectangle(this.Location, this.Size);
}
}
你能提供写代码的方法和类吗? – Valentin
你的班级有一个名为'Cursor'的字段吗? –