April 2006
Beginner
1114 pages
98h 16m
English
form.ScrollBars [= fmScrollBars]
Sets or returns how scrollbars are displayed. Can be one of these settings:
fmScrollBarsNone (default) fmScrollBarsHorizontal fmScrollBarsVertical fmScrollBarsBoth
Depending on the setting of KeepScrollBarsVisible, scrollbars may or may not be visible on a form. The ScrollHeight and ScrollWidth properties determine whether the form is scrollable.
The following code shows how these properties interact by adding 100 lines of text to a label, then resizing the label so that it extends off the form. The UpdateScrollSize procedure calculates the required dimensions for the form and sets ScrollHeight and ScrollWidth so users can view the entire form area:
Private Sub UserForm_Initialize( ) ' Scrollbar settings Me.ScrollBars = fmScrollBarsBoth Me.KeepScrollBarsVisible = fmScrollBarsNone ' Initialize data FillLabel ' Update scrollbars. UpdateScrollSize End Sub ' Adds 100 lines of text to a label, then ' resizes it to demo scrolling a form. Private Sub FillLabel( ) Dim i As Integer Label1.Caption = "" For i = 1 To 100 Label1.Caption = Label1.Caption & _ "Line: " & i & String(90, "*") & vbCrLf Next Label1.AutoSize = True End Sub ' Find the dimensions required to display all of the controls ' on the form and reset ScrollHeight and ScrollWidth to match. Private Sub UpdateScrollSize( ) Dim c As Control, maxHeight As Double, maxWidth As Double For Each c In Me.Controls maxHeight = c.Top + c.height maxWidth = c.Left + c.width If maxHeight > Me.ScrollHeight ...
Read now
Unlock full access