ZOrder 方法、TextBox 控件示例

以下示例设置 TextBoxz 顺序,以便用户可以通过将其置于 z 顺序) 的前面来显示整个 TextBox (,或者通过将 TextBox 发送到 z 顺序) 的背面,将 TextBox 置于其他控件的后面 (。

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

  • 三个名称分别为"TextBox1"到"TextBox3"的 TextBox 控件。
  • 一个名为"ToggleButton1"的 ToggleButton
Private Sub ToggleButton1_Click() 
If ToggleButton1.Value = True Then 
 TextBox2.ZOrder(fmTop) 
 'Place TextBox2 on Top of z-order 
 
 'Update ToggleButton caption to identify next state 
 ToggleButton1.Caption = "Send TextBox2 to back" 
Else 
 TextBox2.ZOrder(1) 
 'Place TextBox2 on Bottom of z-order 
 
 'Update ToggleButton caption to identify next state 
 ToggleButton1.Caption = "Bring TextBox2 to front" 
End If 
End Sub
Private Sub UserForm_Initialize() 
'Set up text boxes to show z-order in the form 
TextBox1.Text = "TextBox 1" 
TextBox2.Text = "TextBox 2" 
TextBox3.Text = "TextBox 3" 
 
TextBox1.Height = 40 
TextBox2.Height = 40 
TextBox3.Height = 40 
 
TextBox1.Width = 60 
TextBox2.Width = 60 
TextBox3.Width = 60 
 
TextBox1.Left = 10 
TextBox1.Top = 10 
 
TextBox2.Left = 25 'Overlap TextBox2 on TextBox1 
TextBox2.Top = 25 
 
TextBox3.Left = 40 'Overlap TextBox3 on TextBox2, TextBox1 
TextBox3.Top = 40 
 
ToggleButton1.Value = False 
ToggleButton1.Caption = "Bring TextBox2 to Front" 
ToggleButton1.Left = 10 
ToggleButton1.Top = 90 
ToggleButton1.Width = 50 
ToggleButton1.Height = 50 
 
End Sub

支持和反馈

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