private bool _dragging = false; private Point _lastPosition = Point.Empty; private Point zoompoint = Point.Empty; private Point startingPoint = Point.Empty; private Point movingPoint = Point.Empty; private bool panning = false; private void pictureBox1_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { if (!_grayscale) return; _lastPosition = e.Location; _dragging = true; } else if (e.Button == MouseButtons.Right) { panning = true; startingPoint = new Point(e.Location.X - movingPoint.X, e.Location.Y - movingPoint.Y); } } private void pictureBox1_MouseUp(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Left) { _dragging = false; } else if (e.Button == MouseButtons.Right) { panning = false; } } private void pictureBox1_MouseLeave(object sender, EventArgs e) { _dragging = false; } private void pictureBox1_MouseMove(object sender, MouseEventArgs e) { if (e.Button == System.Windows.Forms.MouseButtons.Left) { if (!_dragging) return; _image.WindowWidth += e.X - _lastPosition.X; _image.WindowCenter += e.Y - _lastPosition.Y; _lastPosition = e.Location; DisplayImage(_image); } else if (e.Button == System.Windows.Forms.MouseButtons.Right ) { if (panning) { movingPoint = new Point(e.Location.X - startingPoint.X, e.Location.Y - startingPoint.Y); pictureBox1.Invalidate(); } } }
var
This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)