鼠标位置由ViewList控制

时间:2017-07-26 02:14:25

标签: c#

所以我有这个模拟鼠标移动的Window应用程序,我做了一些测试并设法"记录"鼠标移动并播放一次。现在我想创建一个包含2列(" X"和#34; Y)的Viewlist,其中包含我希望鼠标遵循的路线的坐标。可以通过" ycoord"添加坐标。和" xcoord" textlabels,可以添加" button1"按钮到视图列表。还有一个" button2"作为"切换"按钮打开和关闭它。所以,我想要的是,每当我按下左键单击鼠标(LButton)时,只要我按住此按钮,运动就会运行,如果我再次按住它,它会重新开始。我已经管理了文本标签以将内容放入视图列表中,但我不知道如何阅读视图列表并将其转换为鼠标移动坐标。 enter image description here

提前感谢您的帮助!

1 个答案:

答案 0 :(得分:0)

您必须将X,Y坐标保存在列表中,这样您就可以创建一个点列表,然后您必须迭代它并将其用于:

查看对象Cursor here

你也有代码:

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

试试这个:

public partial class Form1 : Form
    {
        private List<Point> _points = null;

        public Form1()
        {
            InitializeComponent();

            _points = new List<Point>();

            this.MouseMove += Form1_MouseMove;
        }

        private void Form1_MouseMove(object sender, MouseEventArgs e)
        {
            //Save the point
            _points.Add(new Point(e.X, e.Y));
        }

        private void PerformRecord()
        {
            foreach (var point in _points)
            {
                this.Cursor = new Cursor(Cursor.Current.Handle);
                Cursor.Position = new Point(point.X, point.Y);
            }
        }

        private void button1_Click(object sender, EventArgs e)
        {
            PerformRecord();
        }
    }