Zooming / stretching a picturebox on current mouse position?

前端 未结 2 1969
情歌与酒
情歌与酒 2021-01-14 04:21

Q: How can I implement zooming on current mouse position over a picturebox, something like zooming in Google Maps?

I am designing a simple GIS / ma

相关标签:
2条回答
  • 2021-01-14 04:39

    the code below zoomed and stretched the pictureBox on the current mouse position

    pictureBox1.Width = (int)(pictureBox1.Width * zoomratio );
    pictureBox1.Height = (int)(pictureBox1.Height * zoomratio );                
    pictureBox1.Top = (int)(e.Y - zoomratio * (e.Y - pictureBox1.Top));
    pictureBox1.Left = (int)(e.X - zoomratio * (e.X - pictureBox1.Left));
    
    0 讨论(0)
  • 2021-01-14 04:50

    I managed to tweak the calculation of the location in this line of code. It's working fine, it is zooming just the way I need it.

    pbxMapa.Location = new Point(pbxMapa.Location.X + (int)(((pbxMapa.Location.X - mouseXPbx) / 10) * zoomRatio), pbxMapa.Location.Y + (int)(((pbxMapa.Location.Y - mouseYPbx) / 10) * zoomRatio));
    
    0 讨论(0)
提交回复
热议问题