private void panel1_MouseMove(object sender, MouseEventArgs e) { if (!canMove) { return; } //PictureBox picturebox = sender as PictureBox; Point p = new Point(0, 0); if (!User32DllHelper.GetCursorPos(ref p)) { MessageBox.Show("User32DllHelper.GetCursorPos获取坐标失败!"); return; } //label2.Text = string.Format("移动时的坐标:x:{0},y:{1}", p.X, p.Y); Move(originalLocation, originalPoint, p, this.pictureBox1); //GC.Collect(); }
private void panel1_MouseDown(object sender, MouseEventArgs e) { if (e.Button != System.Windows.Forms.MouseButtons.Left) { return; } Point p = new Point(0, 0); if (!User32DllHelper.GetCursorPos(ref p)) { MessageBox.Show("User32DllHelper.GetCursorPos获取坐标失败!"); return; } //label1.Text = string.Format("鼠标点下时的坐标:x:{0},y:{1}",p.X,p.Y); originalPoint = p; originalLocation = this.pictureBox1.Location; canMove = true; }
private void panel1_MouseUp(object sender, MouseEventArgs e) { if (e.Button != System.Windows.Forms.MouseButtons.Left) { return; } if (!canMove) { return; } Point p = new Point(0, 0); if (!User32DllHelper.GetCursorPos(ref p)) { MessageBox.Show("User32DllHelper.GetCursorPos获取坐标失败!"); return; } //label2.Text = string.Format("鼠标松开时的坐标:x:{0},y:{1}", p.X, p.Y); Move(originalLocation, originalPoint, p, this.pictureBox1); canMove = false; }