2016-10-27 194 views
0

我正在研究一个简单的程序,它读取鼠标坐标的位置并在标签内显示它们。现在我的问题是:鼠标位置的动态坐标

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

例如:

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

http://stackoverflow.com/questions/8050825/how-to-move-mouse-光标使用-C – Mahdi

回答

0

从@马赫迪的评论,适用于您的情况:

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