Tag 属性示例
下例用 Tag 属性来储存用户窗体上每一控件的附加信息。用户单击一控件,然后单击命令按钮,有关控件的 Tag 的内容被返回文本框中。
窗体包含:
- 名为 TextBox1 的文本框。
- 名为 CommandButton1 的命令按钮。
- 名为 ScrollBar1 的滚动条。
- 名为 ComboBox1 的组合框。
- 名为 MultiPage1 的多页控件。
Sub UserForm_CommandButton1_Click()
UserForm_TextBox1.Text = UserForm_TextBox1.Tag
End Sub
Sub UserForm_Initialize()
UserForm_TextBox1.Locked = True
UserForm_TextBox1.Tag = "Display area for Tag properties."
UserForm_TextBox1.AutoSize = True
UserForm_CommandButton1.Caption = "Show Tag of Current " _
& "Control."
UserForm_CommandButton1.AutoSize = True
UserForm_CommandButton1.WordWrap = True
UserForm_CommandButton1.TakeFocusOnClick = False
UserForm_CommandButton1.Tag = "Shows tag of control that has the focus."
UserForm_ComboBox1.Style = 2
UserForm_ComboBox1.Tag = "ComboBox Style is that of a ListBox."
UserForm_ScrollBar1.Max = 100
UserForm_ScrollBar1.Min = -273
UserForm_ScrollBar1.Tag = "Max = " & UserForm_ScrollBar1.Max & " , Min = " & UserForm_ScrollBar1.Min
UserForm_MultiPage1.Pages.Add
UserForm_MultiPage1.Pages.Add
UserForm_MultiPage1.Tag = "This MultiPage has " & UserForm_MultiPage1.Pages.Count & " pages."
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27