C# - Cursor position (all screen) [duplicate]

我是研究僧i 提交于 2020-01-17 07:44:29

问题


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?


回答1:


you can use Cursor.Position :

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

btw , welcome to SO , please Consider searching the site before asking questions.

and for getting these result every 50 ms you need to use Timer , here's a tutorial for Timer : C# Timer Tutorial

Update :

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


来源:https://stackoverflow.com/questions/17009075/c-sharp-cursor-position-all-screen

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!