鼠标位置的动态坐标

本文关键字:坐标 动态 位置 鼠标 | 更新日期: 2023-09-27 18:15:09

我正在编写一个简单的程序,该程序读取鼠标坐标的位置并将它们显示在标签中。现在我的问题是:

我可以在textbox1textbox2内设置位置坐标(一个用于x,第二个用于y),以便鼠标指针在我写入参数后立即改变其实际位置吗?

例如:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    e.location.x = textbox1.text;
    e.location.y = textbox2.text;
}

鼠标位置的动态坐标

摘自@Mahdi的评论,根据你的情况改编:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    int x = Int32.Parse(textbox1.text);
    int y = Int32.Parse(textbox2.text);
    this.Cursor = new Cursor(Cursor.Current.Handle);
    Cursor.Position = new Point(Cursor.Position.X - x, Cursor.Position.Y - y);
    Cursor.Clip = new Rectangle(this.Location, this.Size);
}