- c - 在位数组中找到第一个零
- linux - Unix 显示有关匹配两种模式之一的文件的信息
- 正则表达式替换多个文件
- linux - 隐藏来自 xtrace 的命令
我正在使用这个函数来移动光标。
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
当我使用热键触发它时,光标将移动到正确的坐标,下次我移动鼠标时它会从该位置继续。按预期工作。
但是我需要在 MouseMove 事件期间触发 SetCursorPos。如果用户将鼠标移动到某个区域,我希望它跳到另一个地方并从那里继续。但是现在它跳到目的地然后立即跳回来(90% 的时间)。我怎样才能避免这种行为?
编辑:我决定通过为 1 个 mousemove 事件将光标剪裁成 1 x 1 px 的正方形来解决这个问题。 Cursor.Clip(MousePosition, new Rectangle(1, 1));
最佳答案
我的猜测是在您的表单顶部您想要触发事件的区域中还有另一个控件。如果是这样,该控件正在捕获 MouseMove
事件。
例如,在这里我在左上角的位置 0, 0 添加了一个绿色的 200x200 面板。如果鼠标移到面板上,窗体的 MouseMove
事件将停止捕获鼠标光标位置。在我的表单的 mouse_move
事件中,我将表单的文本设置为显示鼠标坐标。请注意,当鼠标实际上位于 0, 0 时,窗口文本中的坐标仍然是 200, 200(由于必须单击 SnippingTool.exe 才能获取屏幕截图,因此看不到我的光标)。
要解决此问题,请在面板的 MouseMove
事件(或您正在使用的任何控件)中使用您放置在表单的 MouseMove
事件中的相同代码。这会导致表单文本中的坐标正确。
这是代码(这显然可以重构为一个方法):
public partial class Form1 : Form
{
[DllImport("user32.dll")]
static extern bool SetCursorPos(int X, int Y);
public Form1()
{
InitializeComponent();
}
private void Form1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = string.Format("X: {0}, Y: {1}", e.X, e.Y);
if (e.X >= 0 && e.X <= 200)
{
if (e.Y >= 0 && e.Y <= 200)
{
SetCursorPos(500, 500);
}
}
}
private void panel1_MouseMove(object sender, MouseEventArgs e)
{
this.Text = string.Format("X: {0}, Y: {1}", e.X, e.Y);
if (e.X >= 0 && e.X <= 200)
{
if (e.Y >= 0 && e.Y <= 200)
{
SetCursorPos(500, 500);
}
}
}
}
关于c# reliable MouseMove (hop) 收藏,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15606335/
我们目前正在为我们将进行的贸易研究制定评估标准。 我们选择的标准之一是可靠性(和/或稳健性 - 它们是否相同?)。 您如何评估该软件是否可靠,而无需花费太多时间对其进行评估? 编辑:按照 KenG 给
所以,前几天我正在和一个人谈论企业库日志记录应用程序块和 log4net。 我注意到的一点是 log4net 声称: log4net is not reliable. It is a best-eff
目标: 假设,我在基于 Azure Service Fabric 的 Web 应用程序上有一个非常受欢迎的页面(假设每 5 分钟有 100 万人)。我想在数据层和前端 API 层之间创建某种缓存层。
这是一个关于 Windows 编程的一般问题: Window 消息“可靠”吗? 例如示例(这些只是示例): 您能确定 WM_MOUSEMOVE 会在光标进入屏幕之前发生吗? 您能否确定插入设备后会收到
在衡量网页性能时是否有可接受的信标数据丢失标准,以及计算这些丢失的标准方法? 许多用户没有支持 Navigator.sendBeacon 的浏览器,甚至那个 API 也不能保证无损报告。 似乎最有可能
我是一个由35个程序员组成的团队的发布工程师。我们正在研究PHP,Java,C#和SQL。我们目前使用Subversion,它已经运行了大约一年。我们正处于一个冲突越来越普遍的阶段。我们的应用程序占用
简短问题 1 Django's documentation 中定义的生产环境由什么构成大约 1/2 的路程? 简短问题 2 如果多人同时访问数据库,是否有管理界面损坏数据库的记录案例? 背景 我已使用
我有一个有状态服务,其备份逻辑根据 the corresponding documentation 实现 就像这样: protected override async Task RunAsync(Ca
在我的本地环境中(Apache 2.2.26 上的 PHP 5.4.24)$_SERVER["SCRIPT_URL"] 存在,但我读到这个变量并不总是存在,即使我找不到确切的时间和时间。 我想知道这个
我阅读了很多关于 C++11 STL 中内存管理的 SO 帖子,但我找不到真正令人满意的答案。 我的情况:我开发了一个长时间运行的服务器[大约运行 4-6 周]。目前我使用了很多旧 C 代码char
我正在使用这个函数来移动光标。 [DllImport("user32.dll")] static extern bool SetCursorPos(int X, int Y); 当我使用热键触发它时,
我注意到 TAR 中的 -a 选项允许将文件附加到现有存档。这对于创 build 置文件夹的增量备份有多可靠?有没有人可以分享一下经验? 来自 TAR 手册: -A, --catenate, --c
我是 Microsoft Azure Service Fabric 的新手。让我们假装我有一种在 SF 托管的社交网络。每个用户都是这个系统中的Actor。然后其中一些变得流行。我的意思是有很多人在观
我有一个内置于 OpenTURNS 中的可靠性模型,该模型具有多个极限状态函数,可以接受 2 到 8 个随机变量 (RV)。我最初的尝试是定义一个包含所有八个变量的单个 RandomVector,并将
我有两个 Service Fabric 应用程序。第一个是 Asp.Net Core Service Fabric,第二个是使用计时器运行的 Actor Service。 两者都是用 Serilog
我在 Silverlight 中遇到的主要问题之一是它缺乏强大的命令支持(ala WPF)。更具体地说,我发现很难干净地应用 MVVM 模式并进行合理的封装,因为需要在任何可能影响命令状态的属性上手动
在可靠集合(特别是 IReliableDictionary)中,实现“常见”查询的方法是更新辅助字典,该字典构造要在枚举中以特定方式排序的键。对于大型数据集,我希望避免传输大量数据。 为了实现这一目标
不同的浏览器以古怪的方式运行,有时我们会利用 hack 使 CSS 在所有浏览器中看起来都符合我们的要求。但是,这是在您已经开始将 HTML 和 CSS 放在一起之后要做的事情。 但我发现,要确保您在
我正在使用 MEAN 堆栈,并希望确保某些路由具有经过身份验证的用户。我一直在阅读 JSON Web token 。这似乎很合理。 在我投入更多时间之前,我想询问是否有其他人使用它,以及他们到目前为止
在 React 文档中,onLoad 事件被列在“图像事件”下,但没有大张旗鼓。比较 jQuery 的 .load() 文档及其长长的警告列表,以及对 https://github.com/desan
我是一名优秀的程序员,十分优秀!