Panning a picturebox control

bjwade62

Well-known member
Joined
May 25, 2006
Messages
50
Programming Experience
3-5
I have a picturebox control that I want to create a pan movement that follows the cursor's movement.

I need some help getting started. I've looked at mouse down/up events along with the cursor.location property but can't seem to get it working.

Any ideas?
Thanks
 
Here is an idea, it works fine (here) but you perhaps want to refine it. I put a PictureBox control inside a Panel control. Picturebox.SizeMode=AutoSize and image is larger than Panel. Panel.AutoScroll=True creates scrolls around the bigger image. Panel.MouseMove didn't respond but Picturebox.MouseMove did. Here is the code used:
VB.NET:
Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) _
Handles PictureBox1.MouseMove
    Dim pt As Point = Panel1.PointToClient(PictureBox1.PointToScreen(e.Location))
    If pt.X < Panel1.Width \ 2 Then
        If Panel1.HorizontalScroll.Value > Panel1.HorizontalScroll.Minimum Then
            Panel1.HorizontalScroll.Value -= 1
        End If
    Else
        If Panel1.HorizontalScroll.Value < Panel1.HorizontalScroll.Maximum Then
            Panel1.HorizontalScroll.Value += 1
        End If
    End If
    If pt.Y < Panel1.Height \ 2 Then
        If Panel1.VerticalScroll.Value > Panel1.VerticalScroll.Minimum Then
            Panel1.VerticalScroll.Value -= 1
        End If
    Else
        If Panel1.VerticalScroll.Value < Panel1.VerticalScroll.Maximum Then
            Panel1.VerticalScroll.Value += 1
        End If
    End If
    Panel1.Refresh()
End Sub
 
Back
Top