在Windows窗体中移动鼠标光标

时间:2015-08-28 00:07:36

标签: c# .net winforms

我想创建一个按WASD键移动光标的程序。我创建了一个表单,因为很难将Keyboard.IsKeyDown(Key.W)放在脚本中。

这是我到目前为止的代码:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Input;

namespace keyboardMouse
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void rdnbtnMove_CheckedChanged(object sender, EventArgs e)
        {
            if (Keyboard.IsKeyDown(Key.W))
            {
                    Cursor.Position = new System.Drawing.Point(      
                        Cursor.Position.Y + 5);
            }
        }
    }
}

然而,它会抛出此错误

  

会员' Cursor.Position'无法使用实例访问   参考;使用类型名称来限定它

我该如何解决这个问题?任何帮助表示赞赏。

1 个答案:

答案 0 :(得分:1)

您的代码所在的Form具有Cursor属性。这不是您想要访问的内容。

相反,完全限定类型,如错误所示:

System.Windows.Forms.Cursor.Position