I have a graphical application in which I move a graphic object with the mouse.
In some conditions, the object stops moving. I need then to stop moving the mouse cursor too.
Is it possible? MousePosition
property seems to be in ReadOnly.
Eg.
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X > 100)
{
Cursor.Position = new Point(100, Cursor.Position.Y);
}
}
}
EDIT, second version, works, but the cursor is not "stable" - flickering:
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
if (e.X > 100)
{
Point mousePosition = this.PointToClient(Cursor.Position);
mousePosition.X = 100;
Point newScreenPosition = this.PointToScreen(mousePosition);
Cursor.Position = newScreenPosition;
}
}