在 C# WPF 中获取光标位置 X 和 Y 不变的时刻
我想获得光标位置不变的时刻。我的意思是当鼠标停止时,我想做点什么。但我会这样做很多次。我使用调度程序计时器。但它不允许我在里面做同样的事情。例子:
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick += (sd, args) => // this is triggered when mouse stops.
{
if (a== b)
{
I do something here }; // it works until here.
}
timer2.Tick += (sd, args ) => // // It doesnt allow me to put this timer here.
{
I will do something here when mouse stops.
}
};
I want to get the moment of the unchanging cursor position. I mean when mouse stops, I want to do something. But I will do this many times.I used dispatcher timer. But It doesnt allow me to do same thing inside of that. Example:
timer.Interval = new TimeSpan(0, 0, 0, 1);
timer.Tick += (sd, args) => // this is triggered when mouse stops.
{
if (a== b)
{
I do something here }; // it works until here.
}
timer2.Tick += (sd, args ) => // // It doesnt allow me to put this timer here.
{
I will do something here when mouse stops.
}
};
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
试试这个:
Try this :
您可以尝试在鼠标停止移动 1 秒后获取 X 和 Y 鼠标位置。不需要双计时器等。只需为您的窗口注册 MouseMove 事件并在每次移动时重置计时器。
Here's what you can try to get X and Y mouse position after the mouse has stopped moving for 1 sec. No need for double timers etc. Just register the MouseMove event for your window and reset the timer everytime it moves.
你说的是红色的波浪线吗?
这有帮助吗?我重命名了参数,因为您正在重新定义它们,并且我之前在这种情况下遇到过红色波浪线......
Red squiggly lines you say?
Does this help? I renamed the arguments, since you're redefining them and I have run into red squiggly lines in this case before...