ZOrder 方法、文本框控件示例
下例设置文本框的 Z-顺序,使用户可以显示整个文本框(通过将其置于 Z-顺序的最前面);或者可以把文本框置于其他控件的后面(通过将其置于 Z-顺序的最后)。
窗体包含:
- 名为 TextBox1 到 TextBox3 的三个文本框控件。
- 名为 ToggleButton1 的切换按钮。
Sub UserForm_ToggleButton1_Click()
If UserForm_ToggleButton1.Value = True Then
UserForm_TextBox2.ZOrder (fmTop)
'将 TextBox2 置于 z-顺序的顶端
'更新 ToggleButton 题注来标识下一个状态
UserForm_ToggleButton1.Caption = "Send TextBox2 to back"
Else
UserForm_TextBox2.ZOrder (1)
'将 TextBox2 置于 z-顺序的底端
'更新 ToggleButton 题注来标识下一个状态
UserForm_ToggleButton1.Caption = "Bring TextBox2 to front"
End If
End Sub
Sub UserForm_Initialize()
'建立文本框,在窗体中显示 z-order 顺序
UserForm_TextBox1.Text = "TextBox 1"
UserForm_TextBox2.Text = "TextBox 2"
UserForm_TextBox3.Text = "TextBox 3"
UserForm_TextBox1.Height = 40
UserForm_TextBox2.Height = 40
UserForm_TextBox3.Height = 40
UserForm_TextBox1.Width = 60
UserForm_TextBox2.Width = 60
UserForm_TextBox3.Width = 60
UserForm_TextBox1.Left = 10
UserForm_TextBox1.Top = 10
UserForm_TextBox2.Left = 25 '将 TextBox2 重叠于 TextBox1 上
UserForm_TextBox2.Top = 25
UserForm_TextBox3.Left = 40 '将 TextBox3 重叠于 TextBox2 和TextBox1 之上
UserForm_TextBox3.Top = 40
UserForm_ToggleButton1.Value = False
UserForm_ToggleButton1.Caption = "Bring TextBox2 to Front"
UserForm_ToggleButton1.Left = 10
UserForm_ToggleButton1.Top = 90
UserForm_ToggleButton1.Width = 50
UserForm_ToggleButton1.Height = 50
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
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
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46