C# - 光标位置(所有屏幕)
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/17009075/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
C# - Cursor position (all screen)
提问by
help me please! :) My program should get cursor position (all screen) every ~50 msand them write in text Box. How it make?
请帮帮我!:) 我的程序应该每约 50 毫秒获取一次光标位置(所有屏幕),然后将它们写入 text Box。它是如何制作的?
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?
这是真的吗?
采纳答案by Mehran
you can use Cursor.Position:
你可以使用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.
顺便说一句,欢迎来到 SO,请考虑在提问前搜索该网站。
and for getting these result every 50 ms you need to use Timer, here's a tutorial for Timer: C# Timer Tutorial
为了每 50 毫秒获得一次这些结果,您需要使用Timer这里的教程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();
}

