How to add scroll bar (verticle) to form, something to do with vscrollbar?
Printable View
How to add scroll bar (verticle) to form, something to do with vscrollbar?
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.
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:
You will need to add to your 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
- 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.)
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.
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?