Results 1 to 3 of 3

Thread: VB - Scrollable picture box

Threaded View

  1. #1

    Thread Starter
    Frenzied Member
    Join Date
    Jan 2000
    Location
    Bellevue, WA, USA
    Posts
    1,357

    VB - Scrollable picture box

    Here's how to make a scrollable picture box.
    • Drop a picture box on the form
    • Size it to your desired size
    • Drop another picture box INSIDE the first one
    • Drop a VScrollBar INSIDE the first PictureBox
    • Drop an HScrollBar INSIDE the FIRST PictureBox
    • Drop a TextBox INSIDE the FIRST PictureBox
    • Paste the code below into your form window
    • Either change the path for loading the PictureBox Picture in code, or remove it and set the Picture property manually
    • Run the program and you will have a scrolling picture box
    • The easiest way to put the controls inside the first picture box (IMHO) is to drop them on the form, then select them all, cut them, select the first picture box, and then paste the controls inside.
    You don't have to worry about the location of any controls except the first (container) PictureBox. The code does the rest:
    VB Code:
    1. Option Explicit
    2.  
    3. Private Sub Form_Load()
    4.     ' Setup picture box
    5.     With Picture2
    6.         .AutoSize = True
    7.         .ZOrder 1
    8.         .Picture = LoadPicture("C:\MyPicture.jpe")
    9.         .Move 0, 0
    10.     End With
    11.    
    12.     ' Setup textbox
    13.     With Text1
    14.         .BorderStyle = 0
    15.         .BackColor = Me.BackColor
    16.         .Enabled = False
    17.         .Height = HScroll1.Height
    18.         .Text = ""
    19.         .Width = VScroll1.Width
    20.     End With
    21.    
    22.     ' Setup scroll bars
    23.     ArrangeScrollBars
    24. End Sub
    25.  
    26. Private Sub Form_MouseMove(Button As Integer, Shift As Integer, X As Single, Y As Single)
    27.     Me.MousePointer = vbDefault
    28. End Sub
    29.  
    30. Private Sub Form_Resize()
    31.     ' Adjust scroll bars to new form size
    32.     ArrangeScrollBars
    33. End Sub
    34.  
    35. Private Sub ArrangeScrollBars()
    36.     ' Resize scroll bars to fit form, and set their max value (in relation to form size)
    37.     With HScroll1
    38.         .Move 0, Picture1.ScaleHeight - .Height, Picture1.ScaleWidth - VScroll1.Width
    39.         .Max = IIf((Picture2.ScaleWidth - Picture1.Width + VScroll1.Width) > 0, _
    40.             Picture2.Width - Picture1.ScaleWidth + VScroll1.Width, 0)
    41.         .SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
    42.         .LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
    43.     End With
    44.     With VScroll1
    45.         .Move Picture1.ScaleWidth - .Width, 0, .Width, Picture1.ScaleHeight - HScroll1.Height
    46.         .Max = IIf((Picture2.Height - Picture1.ScaleHeight + HScroll1.Height) > 0, _
    47.             Picture2.Height - Picture1.ScaleHeight + HScroll1.Height, 0)
    48.         .SmallChange = IIf(Int(.Max / 10) > 0, Int(.Max / 10), 1)
    49.         .LargeChange = IIf(Int(.Max / 5) > 0, Int(.Max / 5), 1)
    50.     End With
    51.     With Text1
    52.         .Left = HScroll1.Width
    53.         .Top = VScroll1.Height
    54.         .ZOrder 0
    55.     End With
    56. End Sub
    57.  
    58. Private Sub HScroll1_Change()
    59.     Picture2.Move 0 - HScroll1.Value
    60. End Sub
    61.  
    62. Private Sub HScroll1_Scroll()
    63.     Picture2.Move 0 - HScroll1.Value
    64. End Sub
    65.  
    66. Private Sub VScroll1_Change()
    67.     Picture2.Move Picture2.Left, 0 - VScroll1.Value
    68. End Sub
    69.  
    70. Private Sub VScroll1_Scroll()
    71.     Picture2.Move Picture2.Left, 0 - VScroll1.Value
    72. End Sub
    Last edited by seaweed; Mar 21st, 2003 at 03:57 PM.
    ~seaweed

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