允許在文字方塊中使用多行、自動換行和捲動
下列範例示範TextBox上的MultiLine、WordWrap和ScrollBars屬性。
若要使用本範例,請將此範例程式碼複製到表單的指令碼編輯器中。 若要執行該程式碼,您需要開啟該表單以啟動 Open 事件。 請確定表單包含:
一個名為 TextBox1 的 TextBox 。
四個名稱分別為 ToggleButton1 到 ToggleButton4 的 ToggleButton 控制項。
若要查看置入 TextBox 中的整個文字,請按一下 ToggleButton 控制項將 MultiLine 和 WordWrap 設定為 True。 當 MultiLine 為 True 時,請按住 SHIFT+ENTER 輸入新文字行。 當您手動變更 TextBox 的內容時,將出現 ScrollBars。
Dim ToggleButton1
Dim ToggleButton2
Dim ToggleButton3
Dim ToggleButton4
Dim TextBox1
Sub Item_Open
'Initialize TextBox properties and toggle buttons
Set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton1
Set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton2
Set ToggleButton3 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton3
Set ToggleButton4 = Item.GetInspector.ModifiedFormPages("P.2").ToggleButton4
Set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").TextBox1
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
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
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
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
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 支援與意見反應。