Results 1 to 6 of 6

Thread: Pan and Zoom Image? Any code examples??[RESOLVED]

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Pan and Zoom Image? Any code examples??[RESOLVED]

    I am more interested in the "Pan" feature. I haven't seen much on this so far.

    Thanks!
    Last edited by birthjay; Jan 26th, 2004 at 11:07 AM.

  2. #2
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Hope thisn attachment is enough to be useful.
    Attached Files Attached Files
    This world is not my home. I'm just passing through.

  3. #3

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks!

    Thank you, but I have acheived the same thing just using the "AutoScroll" setting in a "Panel". What I am really trying to do is....


    I have the image loaded. The image is larger than the "Panel" therefore the scrollbars are activated. I can scroll up, down, left, and right.

    What I want is to be able to hold down the left mouse button on the picture and drag (or Pan) the picture within the Panel. I am sure you have seen this in commericial apps.

    Thanks!

  4. #4
    Frenzied Member trisuglow's Avatar
    Join Date
    Jan 2002
    Location
    Horsham, Sussex, UK
    Posts
    1,536
    Using the project I sent you before, delete the two command buttons and put this code into Form1.

    You should be able to click and drag the picture.

    VB Code:
    1. Private blnMoving = False
    2.     Private x As Long
    3.     Private y As Long
    4.  
    5.     Private Sub PictureBox1_MouseDown(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseDown
    6.         PictureBox1.Cursor = Cursors.Hand
    7.         blnMoving = True
    8.         x = e.X
    9.         y = e.Y
    10.     End Sub
    11.  
    12.     Private Sub PictureBox1_MouseMove(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseMove
    13.         If blnMoving Then
    14.             With PictureBox1
    15.                 If e.Button = MouseButtons.None Then
    16.                     .Cursor = Cursors.Arrow
    17.                     blnMoving = False
    18.                 End If
    19.                 .Left += e.X - x
    20.                 .Top += e.Y - y
    21.             End With
    22.  
    23.         End If
    24.     End Sub
    25.  
    26.     Private Sub PictureBox1_MouseLeave(ByVal sender As Object, ByVal e As System.EventArgs) Handles PictureBox1.MouseLeave
    27.         PictureBox1.Cursor = Cursors.Arrow
    28.         blnMoving = False
    29.     End Sub
    30.  
    31.     Private Sub PictureBox1_MouseUp(ByVal sender As Object, ByVal e As System.Windows.Forms.MouseEventArgs) Handles PictureBox1.MouseUp
    32.         PictureBox1.Cursor = Cursors.Hand
    33.         blnMoving = True
    34.     End Sub
    This world is not my home. I'm just passing through.

  5. #5

    Thread Starter
    Fanatic Member
    Join Date
    Jul 2003
    Posts
    830

    Thanks!

    You are the man!

    Thank you for your help!

  6. #6
    Addicted Member
    Join Date
    Apr 2009
    Location
    Near Dog River (sorta)
    Posts
    160

    Re: Pan and Zoom Image? Any code examples??[RESOLVED]

    This code worked for me.... in terms of panning with the mouse.

    Does anyone have any ideas on how to prevent the picture from extending beyond the bounds of the PictureBox/Panel?

    IOW: the picture should not pan such that there is whitespace at any border.
    Last edited by JugglingReferee; May 27th, 2009 at 02:29 PM.
    PC #1: Athlon64 X2+Vista64+VS2008EE+.NET3.5 #2: XP (all flavours Ghost'd)+VS2008EE+.NET3.5
    Help Files: HelpMaker · Dr. Explain · Create Icons: IcoFX


    "Whoever eats my flesh and drinks my blood has eternal life, and I will raise him on the last day." John 6:54

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width