Results 1 to 5 of 5

Thread: [RESOLVED] how to add scrollbar to form

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    81

    Resolved [RESOLVED] how to add scrollbar to form

    How to add scroll bar (verticle) to form, something to do with vscrollbar?

  2. #2
    VB-aholic & Lovin' It LaVolpe's Avatar
    Join Date
    Oct 2007
    Location
    Beside Waldo
    Posts
    19,541

    Re: how to add scrollbar to form

    Double Click on it from the toolbox (vertical or horizontal). Then position it where you want? You might have other questions regarding them, please be more specific.
    Insomnia is just a byproduct of, "It can't be done"

    Classics Enthusiast? Here's my 1969 Mustang Mach I Fastback. Her sister '67 Coupe has been adopted

    Newbie? Novice? Bored? Spend a few minutes browsing the FAQ section of the forum.
    Read the HitchHiker's Guide to Getting Help on the Forums.
    Here is the list of TAGs you can use to format your posts
    Here are VB6 Help Files online


    {Alpha Image Control} {Memory Leak FAQ} {Unicode Open/Save Dialog} {Resource Image Viewer/Extractor}
    {VB and DPI Tutorial} {Manifest Creator} {UserControl Button Template} {stdPicture Render Usage}

  3. #3
    Addicted Member
    Join Date
    Oct 2006
    Posts
    172

    Re: how to add scrollbar to form

    Scrollbars are such a pain in VB6. Here is what I use.

    Note: this is for both horizontal and vertical scrollbars, but it shouldn't be too hard to remove one or the other.

    Code for form:
    Code:
    Dim VSLVal As Integer
    Dim HSLVal As Integer
    Dim HMax As Integer
    Dim VMax As Integer
    
    
    Private Sub Form_Load()
    
    
    On Error Resume Next
    Dim Cntrl As Control
    
    For Each Cntrl In Me.Controls
     If (Not TypeOf Cntrl Is HScrollBar) And _
        (Not TypeOf Cntrl Is VScrollBar) Then
      If (Cntrl.Top + Cntrl.Height + 125) > VMax Then
       VMax = Cntrl.Top + Cntrl.Height + 125
      End If
      If (Cntrl.Left + Cntrl.Width + 125) > HMax Then
       HMax = Cntrl.Left + Cntrl.Width + 125
      End If
     End If
    Next
    On Error GoTo 0
    
    With HS
    .Left = 0
    .Top = Me.ScaleHeight - .Height
    SBar.Height = .Height
    .Width = Me.ScaleWidth - VS.Width
    .Max = HMax - .Width
    If .Max < 0 Then .Max = 0
    End With
    
    With VS
    .Height = Me.ScaleHeight - HS.Height
    .Left = Me.ScaleWidth - .Width
    .Top = 0
    .Max = VMax - .Height
    If .Max < 0 Then .Max = 0
    End With
    
    If HS.Max <= 0 Then HS.Enabled = False
    If VS.Max <= 0 Then VS.Enabled = False
    
    end sub
    Private Sub Form_Resize() 'complete
    If Me.WindowState = 1 Then
     Exit Sub
    ElseIf Me.Height < 2525 Then
     Me.Height = 2525
    ElseIf Me.Width < 2525 Then
     Me.Width = 2525
    End If
    
    With HS
    .Left = 0
    .Top = Me.ScaleHeight - .Height
    .Width = Me.ScaleWidth - VS.Width
    .Max = HMax - .Width
    End With
    
    With VS
    .Height = Me.ScaleHeight - HS.Height
    .Left = Me.ScaleWidth - .Width
    .Top = 0
    .Max = VMax - .Height
    End With
    
    If HS.Max <= 0 Then
     HS.Enabled = False
     HS.Max = 0
    Else
     HS.Enabled = True
    End If
    If VS.Max <= 0 Then
     VS.Enabled = False
     VS.Max = 0
    Else
     VS.Enabled = True
    End If
    End Sub
    
    Private Sub HSPositionChanged() 'complete
    On Error Resume Next
    Dim Val As Integer, Cntrl As Control
    Val = HSLVal - HS.Value
    For Each Cntrl In Me.Controls
     If TypeOf Cntrl Is HScrollBar Or _
        TypeOf Cntrl Is VScrollBar Or _
        TypeOf Cntrl Is Menu Then
     ElseIf TypeOf Cntrl Is Line Then
      Cntrl.x1 = Cntrl.x1 + Val
      Cntrl.x2 = Cntrl.x2 + Val
     Else
      Cntrl.Left = Cntrl.Left + Val
     End If
    Next
    HSLVal = HS.Value
    End Sub
    
    
    Private Sub VSPositionChanged() 'complete
    On Error Resume Next
    Dim Val As Integer, Cntrl As Control
    Val = VSLVal - VS.Value
    For Each Cntrl In Me.Controls
     If TypeOf Cntrl Is HScrollBar Or _
        TypeOf Cntrl Is VScrollBar Or _
        TypeOf Cntrl Is Menu Then
     ElseIf TypeOf Cntrl Is Line Then
      Cntrl.y1 = Cntrl.y1 + Val
      Cntrl.y2 = Cntrl.y2 + Val
     Else
      Cntrl.Top = Cntrl.Top + Val
     End If
    Next
    VSLVal = VS.Value
    End Sub
    Public Sub resizescrolbars()
    'VS.Value = 0
    'HS.Value = 0
    On Error Resume Next
    Dim Cntrl As Control
    For Each Cntrl In Me.Controls
     If (Not TypeOf Cntrl Is HScrollBar) And _
        (Not TypeOf Cntrl Is VScrollBar) Then
      If (Cntrl.Top + Cntrl.Height + 125) > VMax Then
       VMax = Cntrl.Top + Cntrl.Height + 125
      End If
      If (Cntrl.Left + Cntrl.Width + 125) > HMax Then
       HMax = Cntrl.Left + Cntrl.Width + 125
      End If
     End If
    Next
    On Error GoTo 0
    With HS
    .Left = 0
    .Top = Me.ScaleHeight - .Height
    SBar.Height = .Height
    .Width = Me.ScaleWidth - VS.Width
    .Max = HMax - .Width
    If .Max < 0 Then .Max = 0
    End With
    With VS
    .Height = Me.ScaleHeight - HS.Height
    .Left = Me.ScaleWidth - .Width
    .Top = 0
    .Max = VMax - .Height
    If .Max < 0 Then .Max = 0
    End With
    If HS.Max <= 0 Then HS.Enabled = False
    If VS.Max <= 0 Then VS.Enabled = False
    If Me.WindowState = 1 Then
     Exit Sub
    ElseIf Me.Height < 2525 Then
     Me.Height = 2525
    ElseIf Me.Width < 2525 Then
     Me.Width = 2525
    End If
    With HS
    .Left = 0
    .Top = Me.ScaleHeight - .Height
    .Width = Me.ScaleWidth - VS.Width
    .Max = HMax - .Width
    End With
    With VS
    .Height = Me.ScaleHeight - HS.Height
    .Left = Me.ScaleWidth - .Width
    .Top = 0
    .Max = VMax - .Height
    End With
    If HS.Max <= 0 Then
     HS.Enabled = False
     HS.Max = 0
    Else
     HS.Enabled = True
    End If
    If VS.Max <= 0 Then
     VS.Enabled = False
     VS.Max = 0
    Else
     VS.Enabled = True
    End If
    End Sub
    
    Private Sub HS_Change() 'complete
    HSPositionChanged
    End Sub
    Private Sub HS_Scroll() 'complete
    HSPositionChanged
    End Sub
    Private Sub vs_Change() 'complete
    VSPositionChanged
    End Sub
    Private Sub vs_Scroll() 'complete
    VSPositionChanged
    End Sub
    You will need to add to your form:
    - one VScrollBar named VS
    Properties:
    -- Max 32767 , Min 0
    -- SmallChange 225

    - one HScrollbar named HS
    Properties:
    -- Max 32767 , Min 0
    -- SmallChange 225

    - one PictureBox named SBar
    Properties:
    -- Align 2 (align bottom)
    -- Height 8 (You may or may not want to play with this one for looks.)

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Apr 2008
    Posts
    81

    Re: how to add scrollbar to form

    thanks, they are a pain , this is just so I can learn how to use them plus I have a huge form which takes up so much space.

  5. #5
    Lively Member maki's Avatar
    Join Date
    Mar 2006
    Location
    Greece
    Posts
    82

    Re: [RESOLVED] how to add scrollbar to form

    Hello!

    I've added the above code to my form everything works fine except from one frame that i have added to the form. Is there something special about scrollbars and frames?

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