我想在WinForm下实现一个功能,类似于Google Maps中的地图平移,鼠标长按不起,可随意拖动地图,怎么实现这个鼠标长按事件? 在线等,谢谢

解决方案 »

  1.   

    在鼠标Down事件中,做个标记(其他地方标记也可),然后移动是在鼠标的Move事件中做的,判断是否有那个标记,如果有就实时更新坐标,然后在鼠标Up事件中,结束这个动作
      

  2.   

    PictureBox里 设置父容器AutoSize=false; 然后你只需要控制PicutreBox移动就可以了
    显示图形的一部分.当鼠标移动的时候计算矩形位置.截取图形绘制到窗体上
    private Bitmap m_Image = (Bitmap)Image.FromFile(@"大图.bmp");  private Point m_StarPoint = Point.Empty;
      private Point m_ViewPoint = Point.Empty;
      private bool m_StarMove = false;
      private void Form2_Load(object sender, EventArgs e)
      {   
      pictureBox1.Image = m_Image.Clone(new RectangleF(0, 0, pictureBox1.Width, pictureBox1.Height), PixelFormat.Format24bppRgb);   
      }      private void pictureBox1_MouseDown(object sender, MouseEventArgs e)
      {
      Cursor = Cursors.Hand;
      m_StarMove = true;
      m_StarPoint = e.Location;   
      }  private void pictureBox1_MouseMove(object sender, MouseEventArgs e)
      {
      if (m_StarMove)
      {
      System.Threading.Thread.Sleep(100);  LoadImage(new Point(m_StarPoint.X - e.X, m_StarPoint.Y - e.Y));
      }
      }
      private void LoadImage(Point m_MovePoint)
      {
      int _X = m_MovePoint.X + m_ViewPoint.X;
      int _Y = m_MovePoint.Y + m_ViewPoint.Y;
      if (_X < 0) _X = 0;
      if (_Y < 0) _Y = 0;
      if (_X + pictureBox1.Width > m_Image.Width) _X = m_Image.Width - pictureBox1.Width;
      if (_Y + pictureBox1.Height > m_Image.Height) _Y = m_Image.Height - pictureBox1.Height;
      pictureBox1.Image = m_Image.Clone(new RectangleF(_X, _Y, pictureBox1.Width, pictureBox1.Height), PixelFormat.Format24bppRgb);
      m_ViewPoint.X = _X;
      m_ViewPoint.Y = _Y;
      pictureBox1.Refresh();
      }  private void pictureBox1_MouseUp(object sender, MouseEventArgs e)
      {
      m_StarMove = false;
      }