Graphics Manipulations

I am a vb.net 2003 user. I just checked out http://maps.google.com and am very interested in implementing similar graphic manipulation capabilities. They have a map that I can scroll a window into the larger image with the mouse. Precently, I use horizontal and vertical scroll bars and would be interested in knowing how to scroll a large image within a picturebox more efficiently.

thanks,




Answer this question

Graphics Manipulations

  • ansarali

    This is what I am doing now and I use horizontal and vertical scroll bars to pan the image. Paning with the scroll bars is pretty slow and boring for large images. I am interested in being able to pan omni-directionally with the mouse in a similar manner to the maps.google.com. Any suggestions

    Thanks,

    Fred



  • jericmark032785

    Here's some code to get you started (tested with .NET 2.0):

    Public Class Form1
    Dim mMap As Bitmap
    Dim mDragging As Boolean
    Dim mLastpos As New Point, mOffset As New Point

    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
    mMap = Bitmap.FromFile("c:\temp\hubble\image3.jpg")
    mOffset.X = (PictureBox1.Width - mMap.Width) \ 2
    mOffset.Y = (PictureBox1.Height - mMap.Height) \ 2
    End Sub

    Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    mDragging = True
    mLastpos = e.Location
    End Sub

    Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    If Not mDragging Then Exit Sub
    mOffset.X += e.X - mLastpos.X
    mOffset.Y += e.Y - mLastpos.Y
    mLastpos = e.Location
    PictureBox1.Refresh()
    End Sub

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

    Private Sub PictureBox1_Paint(ByVal sender As Object, ByVal e As System.Windows.Forms.PaintEventArgs) Handles PictureBox1.Paint
    e.Graphics.DrawImage(mMap, mOffset.X, mOffset.Y)
    End Sub
    End Class


  • Marcus Adkison

    Put a PictureBox in a Panel then scroll it by changing PictureBox.Top and PictureBox.Left.
    Hope this helps a bit.


  • Graphics Manipulations