我正在做一個項目來控制鼠標,在下面的代碼中,我有點迷路。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'的字段嗎? –