Getting a cursor position value and calling it later
I am stumped as to how I would go about storing the screen/cursor position and calling it back to the exact pixel after it 开发者_运维百科has finished completing the rest of the function.
I am able to run my code when I click a button, but I want to be able to return the cursor to the position it was in when the button was clicked, so I can loop it from that exact location.
Any help would be greatly appreciated
I am writing in C# and using VS2010
It's bad user experience to modify the users cursor, that is why the mouse cursor position is generally exposed as Read-Only information.
In case of Windows Forms (if you are able to use System.Windows.Forms assembly) you can use Position property from Cursor class. It allows you to get and set cursor position. But is's a bad practice to move cursor from your code.
using System.Windows.Forms;
namespace MyApplication
{
class MyClass
{
void Go()
{
var previousPosition = Cursor.Position;
// Do smth
Cursor.Position = previousPosition;
}
}
}
精彩评论