【问题标题】:C# - Cursor position (all screen) [duplicate]C# - 光标位置(全屏)[重复]
【发布时间】:2013-06-09 11:23:28
【问题描述】:

请帮帮我! :) 我的程序应该每 50 毫秒获得一次光标位置(所有屏幕),并且它们写入文本框。 怎么弄的?

例子:

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

但我们获得位置仅在窗口中

真的吗?

【问题讨论】:

  • 这是我见过见过的最难以理解的帖子。
  • 你有googled你的问题吗?
  • 做个好人........

标签: c# cursor-position


【解决方案1】:

你可以使用Cursor.Position

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

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

为了每 50 毫秒获得一次这些结果,您需要使用 Timer ,这里是Timer的教程:C# 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();
    }

【讨论】:

  • 如何每 50 毫秒获取和写入位置?我想了解更多。
  • 你需要使用timer ,你可以通过搜索谷歌找到大量的教程
  • 我会更新我的答案并为你添加一个计时器
  • private void Form1_Load(object sender, EventArgs e) { System.Timers.Timer myTimer = new System.Timers.Timer(50); myTimer.Elapsed += new ElapsedEventHandler(_timer_Elapsed); myTimer.Enabled = true; } static void _timer_Elapsed(object sender, ElapsedEventArgs e) { Cursor.Position.X.ToString(); } ?如何编辑_timer_Elapsed中的textBox?
  • 万岁!!非常感谢!!! ^^
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多