[英]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). 光标更改为点(200,200),但是一旦移动鼠标,光标就会返回到原始点(按钮所在的位置)。
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. 我将注意到,我在2台不同的计算机上运行此程序,其中一台计算机运行正常,而另一台计算机上出现上述问题。
Any suggestions ? 有什么建议么 ?
This might be due to a feature called Snap To and can be enabled or disabled from the control panel. 这可能是由于称为“对齐到”的功能,可以从控制面板启用或禁用该功能。
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);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.