Pan WinForm PictureBox

  • Thread starter Thread starter Jon
  • Start date Start date
This worked for me on a fairly small image. I added a sensitivity that I
through into the calculation to adjust the speed of movement as desired.

Public Class Form1
Dim x1, y1 As Double
Dim scrollSensitivity As Double
Dim md As Boolean
Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
md = True
x1 = Me.Panel1.HorizontalScroll.Value
y1 = Me.Panel1.VerticalScroll.Value
End Sub

Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
scrollSensitivity = 4
If md = True Then
Try
Me.Panel1.HorizontalScroll.Value = (e.X - x1) /
scrollSensitivity
Me.Panel1.VerticalScroll.Value = (e.Y - y1) /
scrollSensitivity
Catch ex As Exception
End Try
End If
End Sub

Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
md = False
End Sub
 
This worked for me on a fairly small image. I added a sensitivity that I
through into the calculation to adjust the speed of movement as desired.

Public Class Form1
    Dim x1, y1 As Double
    Dim scrollSensitivity As Double
    Dim md As Boolean
    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal eAs
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
        md = True
        x1 = Me.Panel1.HorizontalScroll.Value
        y1 = Me.Panel1.VerticalScroll.Value
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal eAs
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
        scrollSensitivity = 4
        If md = True Then
            Try
                Me.Panel1.HorizontalScroll.Value = (e.X- x1) /
scrollSensitivity
                Me.Panel1.VerticalScroll.Value = (e.Y -y1) /
scrollSensitivity
            Catch ex As Exception
            End Try
        End If
    End Sub

    Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As
System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
        md = False
    End Sub

Thanks John, I'll have a go.
 
Back
Top