Hi, I am having a problem with ScrollBars as part of a frame object in that objects in the frame seem to be calling the scroll event when they get focus.
I have a bunch of dynamically created controls on my userform that exist within a Frame.
But when certain controls are clicked within the frame, the frame's scroll event seems to get called automatically. I only want the scroll event to be called when the user actually drags the bar themselves and not when certain controls are clicked.
I have created a simple example to illustrate this problem (just paste the code below into a new userform):
Private Sub UserForm_Initialize()
With Me
.Width = 500
.Height = 300
End With
Dim Frame As MSForms.Frame
Set Frame = Me.Controls.Add("Forms.Frame.1")
With Frame
.Left = 0
.Top = 0
.Width = Me.Width - 10
.Height = Me.Height - 10
.ScrollBars = fmScrollBarsVertical
End With
Dim i As Long
Dim TextBox As MSForms.TextBox
For i = 1 To 10
Set TextBox = Frame.Controls.Add("Forms.TextBox.1")
With TextBox
.Left = 5
.Top = 45 * (i - 1)
.Width = 400
.Height = 45
.Text = i
End With
Next i
Dim max As Long, ctrl As MSForms.Control
max = 0
For Each ctrl In Frame.Controls
If ctrl.Top + ctrl.Height > max Then
max = ctrl.Top + ctrl.Height
End If
Next ctrl
Frame.ScrollHeight = max
End Sub
If you scroll all of the way down to the bottom and then click the textbox numbered 4, you'll see the scrollbar move.
Of course these controls could be created manually and if you put a breakpoint on the Frame's scroll event, you'll see that it is called when textbox 4 is clicked when scrolled all the way down to the bottom.
Is there any way around this?
Thanks in advance.
Taylour
I have a bunch of dynamically created controls on my userform that exist within a Frame.
But when certain controls are clicked within the frame, the frame's scroll event seems to get called automatically. I only want the scroll event to be called when the user actually drags the bar themselves and not when certain controls are clicked.
I have created a simple example to illustrate this problem (just paste the code below into a new userform):
Private Sub UserForm_Initialize()
With Me
.Width = 500
.Height = 300
End With
Dim Frame As MSForms.Frame
Set Frame = Me.Controls.Add("Forms.Frame.1")
With Frame
.Left = 0
.Top = 0
.Width = Me.Width - 10
.Height = Me.Height - 10
.ScrollBars = fmScrollBarsVertical
End With
Dim i As Long
Dim TextBox As MSForms.TextBox
For i = 1 To 10
Set TextBox = Frame.Controls.Add("Forms.TextBox.1")
With TextBox
.Left = 5
.Top = 45 * (i - 1)
.Width = 400
.Height = 45
.Text = i
End With
Next i
Dim max As Long, ctrl As MSForms.Control
max = 0
For Each ctrl In Frame.Controls
If ctrl.Top + ctrl.Height > max Then
max = ctrl.Top + ctrl.Height
End If
Next ctrl
Frame.ScrollHeight = max
End Sub
If you scroll all of the way down to the bottom and then click the textbox numbered 4, you'll see the scrollbar move.
Of course these controls could be created manually and if you put a breakpoint on the Frame's scroll event, you'll see that it is called when textbox 4 is clicked when scrolled all the way down to the bottom.
Is there any way around this?
Thanks in advance.
Taylour