Position of mouse pointer when pointer is not on winform
I can get the position of the mouse when it is in 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 this doesn't work when the pointer is outside the form. Any suggestion?
+3
source to share
1 answer
You can do this in several other ways. Here is a quick and easy way -
private void timer1_Tick(object sender, EventArgs e)
{
lblXPosition.Text = MousePosition.X.ToString();
lblYPosition.Text = MousePosition.Y.ToString();
}
A 500 timer interval is good enough to complete the task. It works even if your pointer is outside the form.
+5
source to share