[英]Changing the colour of tabs of Multipage in 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.我在 VBA 中使用表单,我想知道是否可以使多页中的选项卡在活动时更改颜色,以便与其他选项卡形成更好的对比度。 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?或者您有什么想法可以使活动选项卡相对于非活动选项卡显示得更好?
Approach by marking page captions by a checkmark通过用复选标记标记页面标题的方法
"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)
) and toChrW(&H2611)
并.Tag
property set at any multipage ..._Change()
event ( .Tag
gets initialized via UserForm_Initialize()
firstly)...._Change()
事件中设置的多页.Tag
属性“记住”当前/旧页面索引( .Tag
首先通过UserForm_Initialize()
初始化)。 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.由于标题可能包含普通的空白,我选择在复选标记字符中添加一个受保护的空白 (
ChrW(&HA0)
) 以允许简单的Replace()
保留原始页面标题中的空白。
Example code in Userform用户表单中的示例代码
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
Help functions & UserForm_Initialize()
routine帮助函数和
UserForm_Initialize()
例程
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
One method I've used is to rename the tab when activated, and include more space before and after the page name, so that the tab widens when selected for visibility, or surround with <> etc. chars: <<< TAB_NAME >>>.我使用的一种方法是在激活时重命名选项卡,并在页面名称前后包含更多空格,以便在选择可见性时选项卡会变宽,或者用 <> 等字符包围:<< TAB_NAME >> >. But lately I've considered using separate buttons to activate a page, and change the color.
但是最近我考虑使用单独的按钮来激活页面并更改颜色。 This saves some screenspace as the multipage itself is shorter, buttons can still look like multipage buttons being on the top left of the multipage, but then all the space to the right is free for other controls.
这节省了一些屏幕空间,因为多页本身更短,按钮仍然看起来像多页左上角的多页按钮,但右侧的所有空间都可以用于其他控件。 Actually I use labels setup as command buttonds, generally smaller/less tall.
实际上我使用标签设置作为命令按钮,通常更小/更低。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.