Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Mouse pointer position when pointer is not on winform

I'm able to get the mouse position when it is within the form. Here is my code-

private void Form1_MouseMove(object sender, MouseEventArgs e)
{
    lblXPosition.Text = MousePosition.X.ToString();
    lblYPosition.Text = MousePosition.Y.ToString();
}

But it does not work when the pointer is outside the form. Any suggestion?

like image 235
Code It Avatar asked May 31 '26 11:05

Code It


1 Answers

You can do it some other ways. Here is a quick and simple way-

private void timer1_Tick(object sender, EventArgs e)
{
    lblXPosition.Text = MousePosition.X.ToString();
    lblYPosition.Text = MousePosition.Y.ToString();
}

Timer interval time 500 is well enough to do the job. It works even if your pointer is outside of form.

like image 132
s.k.paul Avatar answered Jun 02 '26 23:06

s.k.paul



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!