NavigationButtons的工作方式有点不同。他们在NavigationControl
容器中进行管理,如果底层按钮被隐藏,容器不会自动调整大小。通过使用该控件的Tag
财产作为临时存储
' 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
可以使这个有很多更通用的,有点“哈克”:
但是,你可以试试这个,它为我工作保持其正常宽度的轨道:
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