문제

Possible Duplicate:
How to track mouse X/Y position and print it to a label?

I seem to have run into a road bump with what seems to be a small problem but can't seem to find the answer. This is my first question asked here, and I apologize if I missed the solution to this question!

I have a toolStripStatusLabel that I want to have the current position of the mouse, I was able to get the coordinates doing this:

private void mouseCoordinatesToolStripStatusLabel()
{
    this.toolStripStatusLabel1.Text = MousePosition.ToString();
    this.Refresh();
}

But this has only been able to get me the mouse's position when I load and not when I move my mouse.

Any help would be appreciated, thank you!

도움이 되었습니까?

해결책

This will give you the mouse cursor coordinates:

...
this.toolStripStatusLabel1.Text = Cursor.Position.X.ToString() + " - " + Cursor.Position.Y.ToString();
...

If you want to be updated on mouse move, just bind the MouseMove event from your Form and add previous code. Actually, yours is ok too, you just seem to be missing to bind the the MouseMove event.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top