MouseMove()事件处理程序 [英] MouseMove() event handler

查看:74
本文介绍了MouseMove()事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

大家好我正在尝试平移绘制到面板上的图像.事情是为了平移它,一旦用户按下鼠标左键并移动按钮,我就需要跟踪鼠标的位置.

好吧,问题是当鼠标移动时,如何确定鼠标的开始和结束位置?如果是鼠标按下事件,则可以在按下鼠标时获取开始位置,而在释放鼠标时可以获取结束位置.但是用鼠标移动动作,如何分辨我正在做的这些小动作的开始和结束呢?

这是我的代码,如果它有助于了解我在说什么

Hi guys. I''m trying to pan an image that I drew to a panel. The thing is in order to pan it, I need to keep track of the mouse location once the user pressed down the left mouse button and move the button.

Well, the problem is when the mouse moves how can I determine the start and end location of the mouse? If it was a mouse down event, I could get the starting location when the mouse is pressed and the end location when it is released. But with the mouse move action, how can one tell the start and end of these small movements that I''m making???

Here is my code if it helps to see what I''m talking about

private void PanPanel_MouseMove(object sender, MouseEventArgs e)
{
        if(e.Button == MouseButtons.Left)
        {
            panStartPoint = e.Location;
            panEndPoint = .... // how do I get this point?
        }

}

推荐答案

您应该处理3个事件:

You should handle 3 events:


  1. MouseDown:在事件处理程序中,您保存 pan
  2. MouseMove的起始位置:在事件处理程序中,您在屏幕上更新视图
  3. MouseUp:在事件处理程序中,使用当前鼠标位置和先前保存的鼠标位置处理 pan

  1. MouseDown: in the event handler you save the starting position for the pan
  2. MouseMove: in the event handler you update the view on screen
  3. MouseUp: in the event handler you process the pan using the current mouse position and the one previously saved


使用MouseDown开始移动-标记您正在移动,开始位置
如果发生MouseDown,请使用MouseMove平移控件.
使用MouseUp结束平移.

[edit]
抱歉,这有点钝.它具有您需要的所有信息,但可以更好地解释.

在MouseDown上,标记您正在移动并记录开始的位置.

在MouseUp上,您标记不再移动.

在MouseMove上,检查是否在移动,如果是,则通过开始位置和当前位置(或最后位置和当前位置-取决于您)之间的差值调整图像位置.

您将获得许多鼠标移动,每个移动都具有新的当前位置.
[/edit]
Use MouseDown to start the move - mark that you are moving, start location
Use MouseMove to pan the control, if MouseDown has happened.
Use MouseUp to end the pan.

[edit]
Sorry, that was a little blunt. It has all the info you need, but could be better explained.

On MouseDown, you mark that you are moving and record the position at which you started.

On MouseUp, you mark you are not moving any more.

On MouseMove, check if you are moving, and if so adjust the image position by the difference between the start and the current position (or the last position and the current - up to you).

You will get a lot of mouse moves, each with the new current position.
[/edit]


这篇关于MouseMove()事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆