鼠标移动灵敏度
我使用 MouseMove 事件来移动对象(例如标签)。
简单原理(示意图):
OnMouseMove(e MouseEventArgs)
if e.Button == Left
deltaX = e.X - lastX
foreach label in labels
label.Location.X += deltaX
lastX = e.X
一旦标签数量增加,我开始看到标签沿着移动轨迹的痕迹。 我有类似 III II III II II III II 的东西,但想要有类似 IIII 的东西作为痕迹。我想知道鼠标何时“开始”和“停止移动”这样的事情。
我沿着水平轴移动标签。 MouseDown
(设置 LastX)并继续。没有人知道什么时候停止,只有鼠标移动的感觉。当然,我可以使用 MouseUp
来知道移动何时结束,但是如果用户保持按下按钮并停止移动,我想反映最新的标签位置。
有没有办法防止这种痕迹呢?
尝试过
label.Visible = false
label.Location.X += deltaX
label.Visible = true
没有帮助。
Parent.SuspendLayout 和 ResumeLayout 没有多大帮助,因为我需要在每次鼠标移动时执行此操作,所以没有任何效果。
I use MouseMove event to move objects(say labels).
simple principle(schematic):
OnMouseMove(e MouseEventArgs)
if e.Button == Left
deltaX = e.X - lastX
foreach label in labels
label.Location.X += deltaX
lastX = e.X
Once the labels number increase, I start to see the labels traces along the moving trajectory.
I have something like I I I II III II I I III II, but want to have something like I I I I as traces. I'd like to know when the mouse "starts" and "stops to move" something like this.
I move labels along a horizontal axe. MouseDown
(set LastX) and go on. Nobody knows when stops, only mouse move sensibility. Surely I can use MouseUp
to know when the movement ends, but however if user maintains the button down and stop moving I want to reflect the latest label position.
Is there a way to prevent this kind of traces?
tried
label.Visible = false
label.Location.X += deltaX
label.Visible = true
does not help.
parent.SuspendLayout and ResumeLayout does not help a lot, because I need doing this at every mouse movement, so any effect.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
编辑:我刚刚注意到您对鼠标何时停止的编辑。您可以使用计时器来帮助您。将其设置为您想要更新位置的时间间隔,并在时间过去后自动重置。鼠标按下时启动,鼠标松开时停止。当计时器到期时,更新标签的位置。
--上下文的原始答案:--
是的,您可以暂停在父控件上绘制,移动标签,然后恢复绘制并刷新。
来自 这个问题:
示例用法:
编辑: 如果您只想在差异大于 n 像素时显示位置的变化,那么您应该使用毕达哥拉斯定理来计算旧位置和新位置之间的距离,并仅当差值大于 n 时才移动它。当鼠标按钮出现时,将标签移动到根据鼠标应有的位置。
伪代码:
Edit: I've just noticed your edit about when the mouse stops. You could use a timer to help you. Have one set to the interval you want to update the positions on and auto reset when it elapses. Start it on mouse down and stop it on mouse up. When the timer elapses, update the locations of the labels.
--Original answer for context:--
Yes, you can suspend drawing on the parent control, move the labels, and then resume drawing and refresh.
From this SO question:
Example Usage:
Edit: If you only want to show the change in position if the difference is greater than n pixels, then you should use the Pythagorean Theorem to calculate the distance between the old position and the new position and only move it if the difference is greater than n. When the mouse button comes up, move the labels to the location they are supposed to be according to the mouse.
Pseudo-code: