用户窗体框架中的滚动条高度不会立即更新。我需要点击它来更新它
Scrollbar height in userform frame doesn't update right away. I need to click it to update it
所以我有一个 Excel 用户表单,其中包含一个框架 。在这个框架中,可能有 X 数量的动态添加 objects 填充它的内容,直到它溢出。当然我添加了一个垂直滚动条来补偿这个问题,这不是问题。
带标题 "Données" 的底部框架是我正在谈论的那个:
这个问题要棘手得多。因此,正如您在上图中看到的那样,有一堆按钮(实际上是切换按钮)。当您切换其中每一个的一组时,它们将出现在下面的框架中。事实上,切换按钮的所有可能组合都会显示。
示例 1:
示例 2:
切换按钮的点击方法实际上是在 class-module 中编程的,它直接在用户窗体(名为 RSAjout2)中调用子程序。
Option Explicit
'THIS PIECE OF CODE IS WRITTEN IN A CLASS-MODULE
' Is not useful for this demonstration
Public WithEvents btn As MSForms.ToggleButton
Public frm As UserForm
'''
' Here, each button is an object that calls the refreshData function to make sure it is updated each
' time one of then is pressed
Private Sub btn_Click()
'We call the subprocedure in the userform RSAjout2
RSAjout2.refreshData
End Sub
调用此子程序(刷新数据)时,其代码中有一部分用于调整滚动条的高度。
Public Sub refreshData()
'###Lots of code that I dont have any problem with###
RSAjout2.CadreDonnees.ScrollHeight = totalHeight
'Where totalHeight is just the height of all the frames stacked in the big frame
End Sub
这也很好用。 (那么问题是什么?)
问题是 当代码实际调整滚动条的高度时,它实际上并没有更新! 我必须点击滚动条本身(并移动它) 使其改变形状或单击另一个切换按钮(但它的状态是旧的)。我用图告诉你。
如果我结合测试和媒体,使框架的数量超过容器框架,它应该在右侧显示一个滚动条(它的高度应该更新)?
错误:
然后,如果我单击滚动条并将其移动到它已经存在的位置,它会突然更新为可见。
为什么?
这只发生在我的 toggleButtons 上。例如,如果我使用我的 "Abondonner" 按钮来更改滚动条的高度,它会完美地工作。为什么会这样?
Private Sub Abandonner_Click()
'Code to test if the scrollbar updates normally from a normal click procedure
Me.CadreDonnees.ScrollHeight = 1000
'Spoiler* It works perfectly
End Sub
编辑:这似乎可以解决问题。但是,这显然不是解决这个问题的最好方法。好吧至少它有效...
'An aweful, but working solution
CadreDonnees.ScrollTop = 1
CadreDonnees.ScrollTop = 0
CadreDonnees.ScrollHeight = totalHeight
CadreDonnees.ScrollTop = 1
CadreDonnees.ScrollTop = 0
尝试调用 Frame 控件的 Repaint
方法 =)
CadreDonnees.Repaint
所以我有一个 Excel 用户表单,其中包含一个框架 。在这个框架中,可能有 X 数量的动态添加 objects 填充它的内容,直到它溢出。当然我添加了一个垂直滚动条来补偿这个问题,这不是问题。
带标题 "Données" 的底部框架是我正在谈论的那个:
这个问题要棘手得多。因此,正如您在上图中看到的那样,有一堆按钮(实际上是切换按钮)。当您切换其中每一个的一组时,它们将出现在下面的框架中。事实上,切换按钮的所有可能组合都会显示。
示例 1:
示例 2:
切换按钮的点击方法实际上是在 class-module 中编程的,它直接在用户窗体(名为 RSAjout2)中调用子程序。
Option Explicit
'THIS PIECE OF CODE IS WRITTEN IN A CLASS-MODULE
' Is not useful for this demonstration
Public WithEvents btn As MSForms.ToggleButton
Public frm As UserForm
'''
' Here, each button is an object that calls the refreshData function to make sure it is updated each
' time one of then is pressed
Private Sub btn_Click()
'We call the subprocedure in the userform RSAjout2
RSAjout2.refreshData
End Sub
调用此子程序(刷新数据)时,其代码中有一部分用于调整滚动条的高度。
Public Sub refreshData()
'###Lots of code that I dont have any problem with###
RSAjout2.CadreDonnees.ScrollHeight = totalHeight
'Where totalHeight is just the height of all the frames stacked in the big frame
End Sub
这也很好用。 (那么问题是什么?)
问题是 当代码实际调整滚动条的高度时,它实际上并没有更新! 我必须点击滚动条本身(并移动它) 使其改变形状或单击另一个切换按钮(但它的状态是旧的)。我用图告诉你。
如果我结合测试和媒体,使框架的数量超过容器框架,它应该在右侧显示一个滚动条(它的高度应该更新)?
错误:
然后,如果我单击滚动条并将其移动到它已经存在的位置,它会突然更新为可见。
为什么?
这只发生在我的 toggleButtons 上。例如,如果我使用我的 "Abondonner" 按钮来更改滚动条的高度,它会完美地工作。为什么会这样?
Private Sub Abandonner_Click()
'Code to test if the scrollbar updates normally from a normal click procedure
Me.CadreDonnees.ScrollHeight = 1000
'Spoiler* It works perfectly
End Sub
编辑:这似乎可以解决问题。但是,这显然不是解决这个问题的最好方法。好吧至少它有效...
'An aweful, but working solution
CadreDonnees.ScrollTop = 1
CadreDonnees.ScrollTop = 0
CadreDonnees.ScrollHeight = totalHeight
CadreDonnees.ScrollTop = 1
CadreDonnees.ScrollTop = 0
尝试调用 Frame 控件的 Repaint
方法 =)
CadreDonnees.Repaint