Results 1 to 4 of 4

Thread: [RESOLVED] Assigning scroll bars to a picture box.

  1. #1

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Resolved [RESOLVED] Assigning scroll bars to a picture box.

    Basically I want to load an image from file into a picture box and keep the picture box at the same size, but be able to scroll around the image using scroll bars.

    I have tried using two scroll bar controls for this, but I can't seem to get it working how I would like.

    Anyone got a decent method or tips on how I can do this?

    Cheers

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Assigning scroll bars to a picture box.

    See Martin's example here.

  3. #3
    Smitten by reality Harsh Gupta's Avatar
    Join Date
    Feb 2005
    Posts
    2,938

    Re: Assigning scroll bars to a picture box.

    add 2 scroll bars (1-vert, 1 horz), and 2 picture boxes (first acts like a container and another contains the picture). and try this code: (you may need to modify a bit, not tested)
    VB Code:
    1. Private Sub Form_Load()
    2.  
    3.     VScroll1.Height = picture1.Height
    4.     HScroll1.Width = picture1.Width
    5.     VScroll1.Max = picture2.Height - picture1.Height
    6.     HScroll1.Max = picture2.Width - picture1.Width
    7.  
    8.     VScroll1.SmallChange = 100
    9.     HScroll1.SmallChange = 100
    10.     VScroll1.LargeChange = picture1.Height
    11.     HScroll1.LargeChange = picture1.Width    
    12. End Sub
    13.  
    14. Public Sub myKeyCodefunc(KeyCode As Integer)
    15.  
    16.     Dim myScrValue As Double
    17.     Dim pageheight As Integer
    18.    
    19.     pageheight = Me.VScroll1.Height
    20.    
    21.     If KeyCode = vbKeyPageUp Or KeyCode = vbKeyPageDown Then
    22.         If KeyCode = vbKeyPageDown Then
    23.             myScrValue = -Me.picture2.Top + pageheight
    24.         Else
    25.             myScrValue = -Me.picture2.Top - pageheight
    26.         End If
    27.        
    28.         If myScrValue > Me.VScroll1.Max Then
    29.             myScrValue = Me.VScroll1.Max
    30.             Me.picture2.Top = -Me.VScroll1.Max
    31.         End If
    32.         If myScrValue > 0 Then
    33.             Me.VScroll1.Value = myScrValue
    34.         Else
    35.             Me.VScroll1.Value = 0
    36.         End If
    37.     End If
    38.    
    39. End Sub
    40.  
    41. Private Sub HScroll1_Change()
    42.  
    43.     picture2.Left = -(HScroll1.Value)
    44.  
    45. End Sub
    46.  
    47. Private Sub Picture2_KeyDown(KeyCode As Integer, Shift As Integer)
    48.  
    49.     myKeyCodefunc KeyCode
    50.    
    51. End Sub
    52.  
    53. Private Sub VScroll1_Change()
    54.  
    55.     picture2.Top = -(VScroll1.Value)
    56.  
    57. End Sub
    Show Appreciation. Rate Posts.

  4. #4

    Thread Starter
    Addicted Member Dayjo's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    130

    Re: Assigning scroll bars to a picture box.

    Thanks Hack, that's just what I needed. (I should have searched really)

    Thanks Harsh Gupta too.

    *Solved*

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