Results 1 to 2 of 2

Thread: Scroll on a form

  1. #1

    Thread Starter
    Hyperactive Member tomjess's Avatar
    Join Date
    Mar 2001
    Location
    Hamilton, New Zealand
    Posts
    348

    Scroll on a form

    What code would one us to put a scroll bar vertically or horizontally on a form. What I mean by this, is I want the user to be able to scroll on my program.

  2. #2
    Megatron
    Guest
    Code:
    Dim VPos As Integer
    Dim HPos As Integer
    
    Private Sub Form_Load()
        'Change the following numbers to the Full height and width of your Form
        intFullHeight = 8000
        intFullWidth = 8000
        'This is the how much of your Form is displayed
        intDisplayHeight = Me.Height
        intDisplayWidth = Me.Width
    
        With VScroll1
            .Height = Me.ScaleHeight
            .Min = 0
            .Max = intFullHeight - intDisplayHeight
            .SmallChange = Screen.TwipsPerPixelX * 10
            .LargeChange = .SmallChange
        End With
        With HScroll1
            .Width = Me.ScaleWidth
            .Min = 0
            .Max = intFullWidth - intDisplayWidth
            .SmallChange = Screen.TwipsPerPixelX * 10
            .LargeChange = .SmallChange
        End With
    End Sub
    
    Sub ScrollForm(Direction As Byte)
        Dim CTL As Control
        
        'Scroll Vertically
        If Direction = 0 Then
            For Each CTL In Me.Controls
                'Make sure it's not a ScrollBar
                If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
                    'If it's a Line then
                    If TypeOf CTL Is Line Then
                        CTL.Y1 = CTL.Y1 + VPos - VScroll1.Value
                        CTL.Y2 = CTL.Y2 + VPos - VScroll1.Value
                    Else
                        CTL.Top = CTL.Top + VPos - VScroll1.Value
                    End If
                End If
            Next
            VPos = VScroll1.Value
        Else
            'Scroll Horizontally
            For Each CTL In Me.Controls
                'Make sure it's not a ScrollBar
                If Not (TypeOf CTL Is VScrollBar) And Not (TypeOf CTL Is HScrollBar) Then
                    'If it's a Line then
                    If TypeOf CTL Is Line Then
                        CTL.X1 = CTL.X1 + HPos - HScroll1.Value
                        CTL.X2 = CTL.X2 + HPos - HScroll1.Value
                    Else
                        CTL.Left = CTL.Left + HPos - HScroll1.Value
                    End If
                End If
            Next
            HPos = HScroll1.Value
        End If
    End Sub
    
    Private Sub HScroll1_Change()
        ScrollForm 1
    End Sub
    
    Private Sub HScroll1_Scroll()
        ScrollForm 1
    End Sub
    
    Private Sub VScroll1_Change()
        ScrollForm 0
    End Sub
    
    Private Sub VScroll1_Scroll()
        ScrollForm 0
    End Sub

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