Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- private void PictureBox1_MouseWheel(object sender, MouseEventArgs e)
- {
- if (e.Delta != 0)
- {
- if (e.Delta <= 0)
- {
- //set minimum size to zoom
- if (pictureBox1.Width < 350)
- return;
- }
- else
- {
- //set maximum size to zoom
- if (pictureBox1.Width > 10000)
- return;
- }
- int[] oldRectX = new int[rectList.Count];
- int[] oldRectY = new int[rectList.Count];
- int oldPictureBoxWidth = pictureBox1.Width;
- int oldPictureBoxHeight = pictureBox1.Height;
- for (int i = 0; i < rectList.Count; i++)
- {
- oldRectX[i] = rectList[i].rectangle.X;
- oldRectY[i] = rectList[i].rectangle.Y;
- }
- pictureBox1.Width += Convert.ToInt32(pictureBox1.Width * e.Delta / 1000);
- pictureBox1.Height += Convert.ToInt32(pictureBox1.Height * e.Delta / 1000);
- for (int i = 0; i < rectList.Count; i++)
- {
- rectList[i].rectangle.Width += Convert.ToInt32(rectList[i].rectangle.Width * e.Delta / 1000);
- rectList[i].rectangle.Height += Convert.ToInt32(rectList[i].rectangle.Height * e.Delta / 1000);
- rectList[i].rectangle.X = Convert.ToInt32(oldRectX[i] * (pictureBox1.Width / oldPictureBoxWidth));
- rectList[i].rectangle.Y = Convert.ToInt32(oldRectY[i] * (pictureBox1.Height / oldPictureBoxHeight));
- rectList[i].SetNewLocationOfSubRectList();
- }
- pictureBox1.Location = new Point((pictureBox1.Parent.ClientSize.Width / 2) - (pictureBox1.Width / 2), (pictureBox1.Parent.ClientSize.Height / 2) - (pictureBox1.Height / 2)); // Set the pictureBox1 to Center
- if (pictureBox1.Width > panel1.Width || pictureBox1.Height > panel1.Height)
- {
- Cursor = Cursors.Hand;
- mouseModeEnum = MouseMode.PANNING;
- }
- else
- {
- mouseModeEnum = MouseMode.NONE;
- Cursor = Cursors.Default;
- }
- pictureBox1.Invalidate();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement