adax
adax

Reputation: 1

Cursor.Position resets automatically?

I have a simple method :

private void button1_Click(object sender, EventArgs e)
{
    System.Windows.Forms.Cursor.Position = new System.Drawing.Point(200, 200);
}

The cursor changes to the point (200,200) but as soon as the mouse is moved the cursor returns back to the original point (where the button is).

I will note that I run this on 2 different computers, on one of them it is working fine, on the other the above problem occurs.

Any suggestions ?

Upvotes: 0

Views: 380

Answers (1)

rene
rene

Reputation: 42453

This might be due to a feature called Snap To and can be enabled or disabled from the control panel.

enter image description here

It makes that the mouse moves to a focussed button.

On other option you might try is to set the focus to a different control:

    private void button1_Click(object sender, EventArgs e)
    {
        // I have a pictureBox1 on my form that I could set the focus to
        this.pictureBox1.Focus();

        System.Windows.Forms.Cursor.Position = new System.Drawing.Point(20, 20);
    }

Upvotes: 2

Related Questions