0

help me please! :) My program should get cursor position (all screen) every ~50 ms and them write in text Box. How it make?

Example:

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
   textBox1.Text = e.X.ToString();
   textBox2.Text = e.Y.ToString();
}

but we get position only in window

it's really do?

4

1 回答 1

11

你可以使用Cursor.Position

   textBox1.Text = Cursor.Position.X.ToString();
   textBox2.Text = Cursor.Position.Y.ToString();

顺便说一句,欢迎来到 SO,请在提问之前考虑搜索该网站。

为了每 50 毫秒获得一次这些结果,您需要使用Timer ,这里有一个教程TimerC# Timer Tutorial

更新 :

    private void Form1_Load(object sender, EventArgs e)
    {
        Timer t1 = new Timer();
        t1.Interval = 50;
        t1.Tick += new EventHandler(timer1_Tick);
        t1.Enabled = true;
    }

    private void timer1_Tick(object sender, EventArgs e)
    {
        textBox1.Text = Cursor.Position.X.ToString();
        textBox2.Text = Cursor.Position.Y.ToString();
    }
于 2013-06-09T11:29:46.470 回答