5

System.Windows.Forms.Cursor を使用せずにマウスの位置を操作する方法はありますか? 相互運用のようなものでしょうか?

これは、System.Windows.Forms を含めることができない特殊な .NET サブセットを使用しているためです。

4

2 に答える 2

7

おっと、質問を読むのが早すぎました。正しい PInvoke 呼び出しです

[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);

ソース: http://www.pinvoke.net/default.aspx/user32.setcursorpos

于 2012-06-19T00:23:34.407 に答える
-2
private void MoveCursor()
{
   // Set the Current cursor, move the cursor's Position,
   // and set its clipping rectangle to the form. 

   this.Cursor = new Cursor(Cursor.Current.Handle);
   Cursor.Position = new Point(Cursor.Position.X - 50, Cursor.Position.Y - 50);
   Cursor.Clip = new Rectangle(this.Location, this.Size);
}
于 2012-06-19T00:34:08.290 に答える