简体   繁体   English

Cursor.Position自动重置?

[英]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.

相关问题 asp.net页面中的Cursor.Position - Cursor.Position in asp.net page 在 Windows 10 中设置 Cursor.Position 无效 - Setting Cursor.Position in Windows 10 not working 为什么在调试时 Cursor.Position 有错误的值? - Why does Cursor.Position have a wrong value while debugging? MousEventArgs.Location和Cursor.Position之间的区别 - The Difference Between MousEventArgs.Location and Cursor.Position 移动光标C#(cursor.position / cursor.clip不起作用) - Moving cursor c# (cursor.position/cursor.clip not working) 为什么用Cursor.Position不能将鼠标光标移动到我告诉它的位置? - Why won't my mouse cursor move where I tell it to go with Cursor.Position? 使用 Cursor.Position、SetCursorPos()、SendInput() 和 mouse_event() 有什么区别? - What's the difference between using Cursor.Position, SetCursorPos(), SendInput() and mouse_event()? C# .NET - SendKeys、SendInput、SendMessage、InputInjector 和 Cursor.Z52F5E0BC3869BCE5F58E25C38659BCE5F58E1ZC77 之间的区别 - C# .NET - Difference between SendKeys, SendInput, SendMessage, InputInjector and Cursor.Position WPF文本框,更新文本属性将重置光标位置 - WPF TextBox, Updating Text Property Resets Cursor Position 如何在C#中键入右括号后自动定位光标BETWEEN方法括号? - How to automatically position the cursor BETWEEN method braces after typing the closing brace in C#?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM