Advertisement
Guest User

Untitled

a guest
May 29th, 2016
53
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. private void PictureBox1_MouseWheel(object sender, MouseEventArgs e)
  2. {
  3. if (e.Delta != 0)
  4. {
  5. if (e.Delta <= 0)
  6. {
  7. //set minimum size to zoom
  8. if (pictureBox1.Width < 350)
  9. return;
  10. }
  11. else
  12. {
  13. //set maximum size to zoom
  14. if (pictureBox1.Width > 10000)
  15. return;
  16. }
  17.  
  18. int[] oldRectX = new int[rectList.Count];
  19. int[] oldRectY = new int[rectList.Count];
  20. int oldPictureBoxWidth = pictureBox1.Width;
  21. int oldPictureBoxHeight = pictureBox1.Height;
  22.  
  23. for (int i = 0; i < rectList.Count; i++)
  24. {
  25. oldRectX[i] = rectList[i].rectangle.X;
  26. oldRectY[i] = rectList[i].rectangle.Y;
  27. }
  28.  
  29. pictureBox1.Width += Convert.ToInt32(pictureBox1.Width * e.Delta / 1000);
  30. pictureBox1.Height += Convert.ToInt32(pictureBox1.Height * e.Delta / 1000);
  31.  
  32. for (int i = 0; i < rectList.Count; i++)
  33. {
  34. rectList[i].rectangle.Width += Convert.ToInt32(rectList[i].rectangle.Width * e.Delta / 1000);
  35. rectList[i].rectangle.Height += Convert.ToInt32(rectList[i].rectangle.Height * e.Delta / 1000);
  36.  
  37. rectList[i].rectangle.X = Convert.ToInt32(oldRectX[i] * (pictureBox1.Width / oldPictureBoxWidth));
  38. rectList[i].rectangle.Y = Convert.ToInt32(oldRectY[i] * (pictureBox1.Height / oldPictureBoxHeight));
  39. rectList[i].SetNewLocationOfSubRectList();
  40. }
  41. 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
  42. if (pictureBox1.Width > panel1.Width || pictureBox1.Height > panel1.Height)
  43. {
  44. Cursor = Cursors.Hand;
  45. mouseModeEnum = MouseMode.PANNING;
  46. }
  47. else
  48. {
  49. mouseModeEnum = MouseMode.NONE;
  50. Cursor = Cursors.Default;
  51. }
  52. pictureBox1.Invalidate();
  53. }
  54. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement