Share via


ZOrder 方法、TextBox 控制項範例

下列範例會設定TextBoxz 順序,讓使用者可以將整個TextBox (移至迭置順序) 的前面,或將TextBox放在其他控制項後面 (,方法是將它傳送至迭置順序) 的背面。

若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定表單包含:

  • 三個名稱分別為 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 支援與意見反應