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?

It'sNotALie.
  • 22,289
  • 12
  • 68
  • 103
  • 1
    This is the most uncomprehendible post I've ever, **ever** seen. – It'sNotALie. Jun 09 '13 at 11:24
  • Have you [googled](https://www.google.co.uk/search?safe=active&site=webhp&source=hp&q=get+mouse+position+in+screen+c%23&oq=get+mouse+position+in+screen+c%23&gs_l=hp.3..0i22i30l5j0i22i10i30j0i22i30j0i22i10i30j0i22i30l2.868.21376.0.21542.43.28.2.10.12.0.402.6149.1j7j4j10j1.23.0...0.0.0..1c.1.16.hp.RSgjyvRkKzE) your question? – Sam Jun 09 '13 at 11:27
  • be nice........ – Andre Dec 18 '20 at 12:42

1 Answers1

11

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();
    }
Mehran
  • 1,409
  • 2
  • 17
  • 27
  • how get and write position every 50ms? I want to know it more. –  Jun 09 '13 at 11:35
  • you need to use `timer` for that , you may find plenty tutorials for that by searching google – Mehran Jun 09 '13 at 11:38
  • I'll update my answer and add a timer to it for you – Mehran Jun 09 '13 at 11:55
  • 1
    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(); } ?how edit textBox in _timer_Elapsed? –  Jun 09 '13 at 11:56
  • Hurray!! Thank you very much!!! ^^ –  Jun 09 '13 at 12:04