Tag 属性示例

以下示例使用 Tag 属性存储有关 UserForm 上每个控件的其他信息。 用户单击控件,然后单击 CommandButton。 在 TextBox 中返回相应控件的 Tag 内容。

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。 确保该窗体包含:

  • 一个名为"TextBox1"的 TextBox
  • 一个名为"CommandButton1"的 CommandButton
  • 一个名为"ScrollBar1"的 ScrollBar
  • 一个名为"ComboBox1"的 ComboBox
  • 一个名为"MultiPage1"的 MultiPage
Private Sub CommandButton1_Click() 
 TextBox1.Text = ActiveControl.Tag 
End Sub 
 
Private Sub UserForm_Initialize() 
 TextBox1.Locked = True 
 TextBox1.Tag = "Display area for Tag properties." 
 TextBox1.AutoSize = True 
 
 CommandButton1.Caption = "Show Tag of Current " _ 
 & "Control." 
 CommandButton1.AutoSize = True 
 CommandButton1.WordWrap = True 
 CommandButton1.TakeFocusOnClick = False 
 CommandButton1.Tag = "Shows tag of control " _ 
 & "that has the focus." 
 
 ComboBox1.Style = fmStyleDropDownList 
 ComboBox1.Tag = "ComboBox Style is that of " _ 
 & "a ListBox." 
 
 ScrollBar1.Max = 100 
 ScrollBar1.Min = -273 
 ScrollBar1.Tag = "Max = " & ScrollBar1.Max _ 
 & " , Min = " & ScrollBar1.Min 
 
 MultiPage1.Pages.Add 
 MultiPage1.Pages.Add 
 MultiPage1.Tag = "This MultiPage has " _ 
 & MultiPage1.Pages.Count & " pages." 
End Sub

支持和反馈

有关于 Office VBA 或本文档的疑问或反馈? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。