解决方法
让我们将“停止移动”定义为“保持在n ms的x像素半径内”.
订阅MouseMove事件并使用计时器(设置为n ms)来设置超时.每次鼠标移动时,请检查公差.如果超出容差范围,请重置计时器并记录新的原点.
伪代码:
Point lastPoint; const float tolerance = 5.0; //you might want to replace this with event subscribe/unsubscribe instead bool listening = false; void OnMouSEOver() { lastpoint = Mouse.Location; timer.Start(); listening = true; //listen to MouseMove events } void OnMouseLeave() { timer.Stop(); listening = false; //stop listening } void OnMouseMove() { if(listening) { if(Math.abs(Mouse.Location - lastPoint) > tolerance) { //mouse moved beyond tolerance - reset timer timer.Reset(); lastPoint = Mouse.Location; } } } void timer_Tick(object sender,EventArgs e) { //mouse "stopped moving" }