Results 1 to 3 of 3

Thread: help with Scroll bars on picture box

  1. #1

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    help with Scroll bars on picture box

    I found this thread http://www.vbforums.com/showthread.p...ox+scroll+bars on how to add scroll bars to my picture box. Now I followed the instructions in the thread but I can't get the scroll bars to work. The image loads but the scroll bars don't resize so I can scroll. Can some one help with this? Here is my code:
    VB Code:
    1. '///////////////////// Select the small photo ////////////////////
    2. Private Sub Drive1_Change()
    3.     Dir1.Path = Drive1.Drive
    4. End Sub
    5.  
    6. Private Sub Dir1_Change()
    7.     File1.Path = Dir1.Path
    8.     File1.Pattern = "*.jpg"
    9. End Sub
    10.  
    11. '/////////// PUT FILE NAME INTO TEXT BOX
    12. Private Sub File1_Click()
    13.     Dim txtPath$
    14.     txtPath$ = Dir1.Path
    15.     Dim Msg   ' Declare variable.
    16.  
    17.         If Mid(txtPath$, Len(txtPath$), 1) = "\" Then
    18.             txt_image.Text = Dir1.Path & File1.FileName
    19.         Else
    20.             txt_image.Text = File1.FileName
    21.         End If
    22.         Picture2.Picture = LoadPicture(Dir1.Path & "\" & File1.FileName)
    23. End Sub
    24.  
    25. Private Sub Form_Load()
    26.     ' Setup picture box
    27.     With Picture2
    28.         .AutoSize = True
    29.         .ZOrder 1
    30.         .Move 0, 0
    31.     End With
    32.      
    33.     ' Setup scroll bars
    34.     ArrangeScrollBars
    35. End Sub
    36.  
    37. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    38.     Me.MousePointer = vbDefault
    39. End Sub
    40.  
    41. Private Sub Form_Resize()
    42.     ' Adjust scroll bars to new form size
    43.     ArrangeScrollBars
    44. End Sub
    45.  
    46. Private Sub ArrangeScrollBars()
    47.     ' Resize scroll bars to fit form, and set their max value (in relation to form size)
    48.     With HScroll1
    49.         .Move 0, Picture1.ScaleHeight - .Height, Picture1.ScaleWidth - VScroll1.Width
    50.         .Max = IIf((Picture2.ScaleWidth - Picture1.Width + VScroll1.Width) > 0, _
    51.             Picture2.Width - Picture1.ScaleWidth + VScroll1.Width, 0)
    52.         .SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
    53.         .LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
    54.     End With
    55.     With VScroll1
    56.         .Move Picture1.ScaleWidth - .Width, 0, .Width, Picture1.ScaleHeight - HScroll1.Height
    57.         .Max = IIf((Picture2.Height - Picture1.ScaleHeight + HScroll1.Height) > 0, _
    58.             Picture2.Height - Picture1.ScaleHeight + HScroll1.Height, 0)
    59.         .SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
    60.         .LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
    61.     End With
    62.    
    63. End Sub
    64.  
    65. Private Sub HScroll1_Change()
    66.     Picture2.Move 0 - HScroll1.Value
    67. End Sub
    68.  
    69. Private Sub HScroll1_Scroll()
    70.     Picture2.Move 0 - HScroll1.Value
    71. End Sub
    72.  
    73. Private Sub VScroll1_Change()
    74.     Picture2.Move Picture2.Left, 0 - VScroll1.Value
    75. End Sub
    76.  
    77. Private Sub VScroll1_Scroll()
    78.     Picture2.Move Picture2.Left, 0 - VScroll1.Value
    79. End Sub
    He who never made a mistake never made a discovery?

  2. #2
    I'm about to be a PowerPoster! Joacim Andersson's Avatar
    Join Date
    Jan 1999
    Location
    Sweden
    Posts
    14,649

    Re: help with Scroll bars on picture box

    If you have the AutoSize property of Picture2 set to True then simply call the ArrangeScrollBars Sub from the Picture2_Resize() event.

  3. #3

    Thread Starter
    Fanatic Member Navarone's Avatar
    Join Date
    Jun 2003
    Location
    Akron, Ohio USA
    Posts
    740

    Re: help with Scroll bars on picture box

    ok, thanks
    He who never made a mistake never made a discovery?

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