Pan WinForm PictureBox

J

John Bundy

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
 
J

Jon

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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top