日期:2014-05-18  浏览次数:20786 次

pictureBox用鼠标拖动后,如何把图片的位置保存下来
我的代码: bool wselected = false;
  bool mouseflag = false;
  Point p = new Point();
  private void pbHeadPicture_MouseDown(object sender, MouseEventArgs e)
  {
  pbHeadPicture.Cursor = Cursors.Hand;
  mouseflag = true;
  wselected = true;
  p.X = e.X;
  p.Y = e.Y;
  }
  int driftX = 0, driftY = 0;
  int mx = 0, my = 0;
  Bitmap bm;
  private void pbHeadPicture_MouseMove(object sender, MouseEventArgs e)
  {
  if (wselected)
  {
  driftX = p.X - e.X;
  driftY = p.Y - e.Y;

  mx = mx - driftX;
  my = my - driftY;
  bm = new Bitmap(pbHeadPicture.Image);
  Graphics g = pbHeadPicture.CreateGraphics();
  g.Clear(pbHeadPicture.BackColor);
  g.DrawImage(bm, mx, my);
  p.X = e.X;
  p.Y = e.Y;

  }
  }

  private void pbHeadPicture_MouseUp(object sender, MouseEventArgs e)
  {
  pbHeadPicture.Cursor = Cursors.Default;
  wselected = false;
  }
哪出了问题?

------解决方案--------------------
我也非常想知道,帮顶!