在 VBA 中更改多页选项卡的颜色 [英] Changing the colour of tabs of Multipage in VBA
问题描述
我在 VBA 中使用表单,我想知道是否可以使多页中的选项卡在活动时更改颜色,以便与其他选项卡形成更好的对比度.这是一个截图
I'm using the Forms in VBA and I was wondering if it is possible to make the tabs in my Multipages change colour when active, so that there is a better contrast with the other tabs. Here is a screenshot
有没有办法对比活动选项卡和非活动选项卡,以便用户知道他正在使用哪个选项卡?
Is there a way to contrast the active tab from the inactive tabs so that the user can know which tab he is using?
或者您有什么想法可以让活动标签相对于非活动标签看起来更好?
Or do you have any idea so that the active tab can appear better against the inactive tabs?
推荐答案
通过勾选标记来标记页面标题
或者您有什么想法可以让活动标签相对于非活动标签看起来更好?" -
一种可能的 &有用的方法是
A possible & helpful approach would be to
- 标记每个点击的页面标题,用复选标记(例如
ChrW(&H2611)
)和to - 自动去标记之前的页面标题:代码通过多页的
.Tag
记住"当前/旧页面索引在任何多页..._Change()
事件中设置的属性(.Tag
首先通过UserForm_Initialize()
初始化).
- mark each clicked page caption by a checkmark (e.g.
ChrW(&H2611)
) and to - automatically de-mark a prior page caption: the code "remembers" the current/old page index via the multipage's
.Tag
property set at any multipage..._Change()
event (.Tag
gets initialized viaUserForm_Initialize()
firstly).
由于字幕可能包含普通空格,我选择在复选标记字符中添加受保护的空格 (ChrW(&HA0)
) 以允许简单的 Replace()
保留原始页面标题中的空白.
As Captions may include normal blanks, I chose to add a protected blank (ChrW(&HA0)
) to the checkmark character to allow a simple Replace()
maintaining the blanks in the original page caption.
用户表单中的示例代码
Private Sub MultiPage1_Change()
'Purpose: mark current page caption by a checkmark
With Me.MultiPage1
Dim pg As MSForms.Page
'a) de-mark old caption
Set pg = oldPage(Me.MultiPage1)
pg.Caption = Replace(pg.Caption, ChkMark, vbNullString)
'b) mark new caption & remember latest multipage value
Set pg = .Pages(.Value)
pg.Caption = ChkMark & pg.Caption
.Tag = .Value ' << remember latest page index
End With
End Sub
帮助功能和UserForm_Initialize()
例程
Help functions & UserForm_Initialize()
routine
Function oldPage(mp As MSForms.MultiPage) As MSForms.Page
'Purpose: return currently marked page in given multipage
With mp
Set oldPage = .Pages(Val(.Tag))
End With
End Function
Function ChkMark() As String
'Purpose: return ballot box with check + blank space
ChkMark = ChrW(&H2611) & ChrW(&HA0) ' ballot box with check + blank
End Function
Private Sub UserForm_Initialize()
'Purpose: mark start page & remember page index
Const startIndx As Long = 0
With Me.MultiPage1
.Pages(startIndx).Caption = ChkMark & .Pages(startIndx).Caption
.Tag = startIndx
End With
End Sub
这篇关于在 VBA 中更改多页选项卡的颜色的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!