设置Mouseposition在WPF [英] Set Mouseposition in WPF

查看:205
本文介绍了设置Mouseposition在WPF的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

可能重复:结果
移动鼠标使用C#

我要取代我的鼠标通过Kinect的手势,但我不能找到一种方法来设置一个WPF应用程序mouseposition。

I'm going to replace my mouse by Kinect gestures but I can't find a way to set mouseposition for a WPF app.

在此先感谢

汤姆

推荐答案

您可以使用 Cursor.Position 属性 System.Windows.Forms的此找到。

You can use the Cursor.Position property found in System.Windows.Forms for this.

由于上演示的 MSDN文档 Cursor.Position

As demonstrated on the MSDN documentation for Cursor.Position:

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

如果您正在寻找这样做Windows窗体之外,你可以做平台调用USER32的 SetCursorPos

If you're looking to do this outside of Windows Forms, you can do a platform invoke on User32's SetCursorPos.

这篇关于设置Mouseposition在WPF的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆