我在用户表单上有两个帧,每帧都有一张图片,图片可以比帧更宽或更高,这就是我需要滚动条的原因。我想要做的是,当用户需要使用第1帧上的水平滚动条时,第2帧上的水平滚动条应采用相同的值。
我正在寻找类似的东西:
Frame1.HorizontalScrollBar.Value
但那不是滚动条的属性。我在网站上发现框架滚动条的事件处理程序是:
Private Sub Frame1_Scroll(ByVal ActionX As MSForms.fmScrollAction, ByVal ActionY As MSForms.fmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)
End sub
我尝试了但是我无法弄清楚当事件被触发时如何将这些值分配给第二个水平滚动条。
答案 0 :(得分:2)
将以下所有内容放入userform代码模块中:
Private bIgnore As Boolean
Private Sub Frame1_Scroll(ByVal ActionX As MSForms.fmScrollAction, ByVal ActionY As MSForms.fmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)
If Not bIgnore Then
bIgnore = 1
Frame2.ScrollLeft = Frame1.ScrollLeft + ActualDx
bIgnore = 0
End If
End Sub
Private Sub Frame2_Scroll(ByVal ActionX As MSForms.fmScrollAction, ByVal ActionY As MSForms.fmScrollAction, ByVal RequestDx As Single, ByVal RequestDy As Single, ByVal ActualDx As MSForms.ReturnSingle, ByVal ActualDy As MSForms.ReturnSingle)
If Not bIgnore Then
bIgnore = 1
Frame1.ScrollLeft = Frame2.ScrollLeft + ActualDx
bIgnore = 0
End If
End Sub
注意:这假设您的帧名为Frame1和Frame2,并且两个帧都配置了相同的ScrollWidth值。