AutoSize、MultiLine、WordWrap、ScrollBars 屬性、TextBox 控制項範例
下列範例示範TextBox上的MultiLine、WordWrap和ScrollBars屬性。
若要使用本範例,請將此範例程式碼複製到表單的宣告部分中。 請確定該表單包含:
- 一個名為 TextBox1 的 TextBox 。
- 四個名稱分別為 ToggleButton1 到 ToggleButton4 的 ToggleButton 控制項。
若要查看置入 TextBox 中的整個文字,請按一下 ToggleButton 控制項將 MultiLine 和 WordWrap 設定為 True。
當 MultiLine 為 True時,您可以按 Shift+Enter 鍵來輸入新行文字。 當您手動變更 TextBox 的內容時,將出現 ScrollBars。
Private Sub UserForm_Initialize()
'Initialize TextBox properties and toggle buttons
TextBox1.Text = "Type your text here. "
& "Enter SHIFT+ENTER to move to a new line."
TextBox1.AutoSize = False
ToggleButton1.Caption = "AutoSize Off"
ToggleButton1.Value = False
ToggleButton1.AutoSize = True
TextBox1.WordWrap = False
ToggleButton2.Caption = "WordWrap Off"
ToggleButton2.Value = False
ToggleButton2.AutoSize = True
TextBox1.ScrollBars = 0
ToggleButton3.Caption = "ScrollBars Off"
ToggleButton3.Value = False
ToggleButton3.AutoSize = True
TextBox1.MultiLine = False
ToggleButton4.Caption = "Single Line"
ToggleButton4.Value = False
ToggleButton4.AutoSize = True
End Sub
Private Sub ToggleButton1_Click()
'Set AutoSize property and associated ToggleButton
If ToggleButton1.Value = True Then
TextBox1.AutoSize = True
ToggleButton1.Caption = "AutoSize On"
Else
TextBox1.AutoSize = False
ToggleButton1.Caption = "AutoSize Off"
End If
End Sub
Private Sub ToggleButton2_Click()
'Set WordWrap property and associated ToggleButton
If ToggleButton2.Value = True Then
TextBox1.WordWrap = True
ToggleButton2.Caption = "WordWrap On"
Else
TextBox1.WordWrap = False
ToggleButton2.Caption = "WordWrap Off"
End If
End Sub
Private Sub ToggleButton3_Click()
'Set ScrollBars property and associated ToggleButton
If ToggleButton3.Value = True Then
TextBox1.ScrollBars = 3
ToggleButton3.Caption = "ScrollBars On"
Else
TextBox1.ScrollBars = 0
ToggleButton3.Caption = "ScrollBars Off"
End If
End Sub
Private Sub ToggleButton4_Click()
'Set MultiLine property and associated ToggleButton
If ToggleButton4.Value = True Then
TextBox1.MultiLine = True
ToggleButton4.Caption = "Multiple Lines"
Else
TextBox1.MultiLine = False
ToggleButton4.Caption = "Single Line"
End If
End Sub
支援和意見反應
有關於 Office VBA 或這份文件的問題或意見反應嗎? 如需取得支援服務並提供意見反應的相關指導,請參閱 Office VBA 支援與意見反應。