Results 1 to 1 of 1

Thread: Scroll Picturebox with resizable form.

  1. #1

    Thread Starter
    Fanatic Member
    Join Date
    Sep 2006
    Location
    London, UK
    Posts
    817

    Scroll Picturebox with resizable form.

    I'd just like to post this in case it helps anyone. Found this on microsoft's website and it did just about what I wanted bar a couple of small modifications other forum members have helped me make.

    It attaches horizontal and vertical scrollsbars to the sides of a picturebox (picture1) if the picturebox is larger than the form or when the form is resized to a size smaller than the picturebox. Suggestions for adding wheelmouse scrolldown would be very welcome.

    1. Start a new project in Visual Basic.
    2. Add a horizontal scroll bar control and a vertical scroll bar control to Form1. (The size doesn't matter because the program automatically sizes the scroll bars in the Form Resize event code.)
    3. Add a picture box control to Form1.
    4. Add the following code to the Form

    VB Code:
    1. Sub Form_Resize()
    2. On Error Resume Next
    3.    ' Position the scroll bars:
    4.    HScroll1.Left = 0
    5.    VScroll1.Top = 0
    6.    If Picture1.Width > ScaleWidth Then
    7.       HScroll1.Top = ScaleHeight - HScroll1.Height
    8.    Else
    9.       HScroll1.Top = ScaleHeight
    10.    End If
    11.    If Picture1.Height > HScroll1.Top Then
    12.       VScroll1.Left = ScaleWidth - VScroll1.Width
    13.       If Picture1.Width > VScroll1.Left Then
    14.          HScroll1.Top = ScaleHeight - HScroll1.Height
    15.       End If
    16.    Else
    17.       VScroll1.Left = ScaleWidth
    18.    End If
    19.    HScroll1.Width = ScaleWidth
    20.    If HScroll1.Top > 0 Then VScroll1.Height = HScroll1.Top
    21.    ' Set the scroll bar ranges
    22.    HScroll1.Max = Picture1.Width - VScroll1.Left
    23.    VScroll1.Max = Picture1.Height - HScroll1.Top
    24.    HScroll1.SmallChange = Picture1.Width / 10
    25.    HScroll1.LargeChange = Picture1.Width - HScroll1.Max
    26.    VScroll1.SmallChange = Picture1.Height / 10
    27.    VScroll1.LargeChange = Picture1.Height - VScroll1.Max
    28.    HScroll1.ZOrder 0
    29.    VScroll1.ZOrder 0
    30. End Sub
    31. Sub HScroll1_Change()
    32.     Picture1.Left = -HScroll1.Value
    33. End Sub
    34. Sub VScroll1_Change()
    35.     Picture1.Top = -VScroll1.Value
    36. End Sub
    37. Private Sub HScroll1_GotFocus()
    38. Picture1.SetFocus
    39. End Sub
    40. Private Sub VScroll1_GotFocus()
    41. Picture1.SetFocus
    42. End Sub
    Last edited by sgrya1; Dec 9th, 2006 at 11:42 AM.

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