有没有办法动态重新排序Access 2010导航表单上的导航按钮?
我想根据用户类型隐藏某些按钮;但是,如果无法修改订单,只需隐藏它们就会在按钮之间留下空隙。
我尝试过以下类似的运气。
Me.NavigationButton1.TabIndex = 1
Me.NavigationButton2.TabIndex = 0
Me.Requery
Me.Refresh
提前谢谢。
答案 0 :(得分:1)
NavigationButtons的工作方式略有不同。它们在NavigationControl
容器中进行管理,如果隐藏了基础按钮,则该容器不会自动调整大小。
但是,你可以尝试这个,它对我有用:
' Always remember the normal size of the button '
Static bt1Witdh as Long
if bt1Width = 0 then bt1Width = Me.NavigationButton1.Width
' Now hide the button '
Me.NavigationButton1.Width = 0
Me.NavigationButton1.Visible = False
' Unhide the button '
Me.NavigationButton1.Visible = true
Me.NavigationButton1.Width = bt1Width
通过使用控件的Tag
属性作为临时存储来跟踪它们的正常宽度,你可以使它更通用,更有点'hacky':
Public Sub HideNavigationButton(bt As NavigationButton)
' Store the width if we haven't already done so '
If bt.Tag = vbNullString Then bt.Tag = CStr(bt.Width)
bt.Width = 0
bt.Visible = False
End Sub
Public Sub ShowNavigationButton(bt As NavigationButton)
If bt.Visible Or bt.Width > 0 Then Exit Sub
bt.Visible = True
bt.Width = CInt(bt.Tag)
End Sub
使用它:
' Hide '
HideNavigationButton Me.NavigationButton1
' Show '
ShowNavigationButton Me.NavigationButton1