我想知道如何更改我的代码,以防止在 PictureBox 放大和处于正常状态时平移超出 PictureBox 的边缘。如果可能的话,我还想知道如何让它在鼠标悬停的当前位置缩放并在缩放时保持图像质量。任何帮助将不胜感激。
这是缩放的代码:
Private Sub PictureBox_MouseWheel(sender As System.Object,
e As MouseEventArgs) Handles PictureBox1.MouseWheel
If e.Delta <> 0 Then
If e.Delta <= 0 Then
If PictureBox1.Width < 500 Then Exit Sub
Else
If PictureBox1.Width > 2000 Then Exit Sub
End If
PictureBox1.Width += CInt(PictureBox1.Width * e.Delta / 1000)
PictureBox1.Height += CInt(PictureBox1.Height * e.Delta / 1000)
End If
End Sub
这是我正在使用的平移代码:
Private Offset As Point
Private Sub Picturebox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
Offset = e.Location
End Sub
Private Sub Picturebox1_MouseMove(ByVal sender As System.Object, ByVal e As MouseEventArgs) Handles PictureBox1.MouseMove
PictureBox1.Select()
If e.Button = Windows.Forms.MouseButtons.Left Then
PictureBox1.Left += e.X - Offset.X
PictureBox1.Top += e.Y - Offset.Y
End If
End Sub