移动鼠标一个PictureBox [英] Move a PictureBox with mouse

查看:109
本文介绍了移动鼠标一个PictureBox的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开发的Windows Mobile(Compact Framework 2.0中)的应用程序。它有一个图片一个wimforms。

I'm developing an app for windows mobile (Compact Framework 2.0). It has a wimforms with a pictureBox.

我想移动的图片框的图像,但我不知道该怎么办,所以我选择移动孔的PictureBox 。要做到这一点我用这个事件:

I want to move the image of the pictureBox but I don't know how to do it so I choose to move the hole pictureBox. To do it I use this event:


private void imagenMapa_MouseMove(object sender, MouseEventArgs e)
{
      imagenMapa.Left = e.X;
      imagenMapa.Top = e.Y;
      this.Refresh();
}



不过,当我移动图片框会闪烁并移动每一个地方。

But when I move the pictureBox it blinks and moves every where.

我在做什么错了?

谢谢!

推荐答案

例如 EY 是相对于图片框(例如,如果鼠标在图片框的左上角,这是0,0)。

The e.X and e.Y are relative to the picture box (e.g. if the mouse is in the upper left of the picture box, that's 0,0) .

imagenMapa.​​Left 值和 imagenMapa.​​Top 是相对于形​​式(或其他控件中包含 imagenMapa

The values for imagenMapa.Left and imagenMapa.Top are relative to the form (or whatever control contains imagenMapa)

如果您尝试值这两个混无需转换系统,你会得到跳跃(就像你所看到的)。

If you try to mix values from these two systems without conversion, you're going to get jumps (like you're seeing).

你可能会更好过鼠标的位置转换为使用同一个坐标系由包含图片框的东西。

You're probably better off converting the mouse position to the same coordinate system used by the thing that contains the picture box.

您可以使用的 imagenMapa.​​PointToScreen 让鼠标在屏幕坐标中的坐标(或的 Cursor.Position 获得位置直接)和 yourForm .PointToClient 让他们回来的形式坐标。

You could use imagenMapa.PointToScreen to get the mouse coordinates in screen coordinates (or Cursor.Position to get the position directly), and yourForm.PointToClient to get them back in the form coordinates.

请注意,根据您的需要,可以实现通过重写/处理的 油漆事件控制和绘制自己的形象。如果你这样做,你可以保持在PictureBox的坐标一切,因为这些是当你所谓的 graphicsObject.DrawImage

Note that depending on your needs, you could accomplish "moving an image within a control" by overriding/handling the Paint event of a control and drawing the image yourself. If you did this, you could keep everything in the picturebox coordinates, since those are likely what you would use when you called graphicsObject.DrawImage.

这篇关于移动鼠标一个PictureBox的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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