控制输入文本框时的选择行为和拖动行为

以下示例使用 DragBehaviorEnterFieldBehavior 属性来演示在输入控件以及将信息从一个控件拖动到另一个控件时可以提供的不同效果。

此示例使用两个 TextBox 控件。 您可以为每个控件设置 DragBehaviorEnterFieldBehavior ,并查看从一个控件拖曳到另一个控件的效果。

若要使用本示例,请将此示例代码复制到窗体的"脚本编辑器"中。 若要运行本代码,需要打开该窗体,以便激活 Open 事件。 确保该窗体包含:

  • 一个名为"TextBox1"的 TextBox

  • 两个名称分别为"ToggleButton1"和"ToggleButton2"的 ToggleButton 控件。 这些控件与 TextBox1 相关。

  • 一个名为"TextBox2"的 TextBox

  • 两个名称分别为"ToggleButton3"和"ToggleButton4"的 ToggleButton 控件。 这些控件和"TextBox2"相关。

Dim TextBox1, TextBox2 
Dim ToggleButton1, ToggleButton2, ToggleButton3, ToggleButton4 
 
Sub Item_Open() 
 set TextBox1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox1") 
 set TextBox2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("TextBox2") 
 set ToggleButton1 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton1") 
 set ToggleButton2 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton2") 
 set ToggleButton3 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton3") 
 set ToggleButton4 = Item.GetInspector.ModifiedFormPages("P.2").Controls("ToggleButton4") 
 
 TextBox1.Text = "Once upon a time in a land ...," 
 ToggleButton1.Value = True 
 ToggleButton1.Caption = "Drag Enabled" 
 ToggleButton1.WordWrap = True 
 TextBox1.DragBehavior = 1 'fmDragBehaviorEnabled 
 
 ToggleButton2.Value = True 
 ToggleButton2.Caption = "Recall Selection" 
 ToggleButton2.WordWrap = True 
 TextBox1.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection 
 
 TextBox2.Text = "XXX, YYYY" 
 ToggleButton3.Value = False 
 ToggleButton3.Caption = "Drag Disabled" 
 ToggleButton3.WordWrap = True 
 TextBox2.DragBehavior = 0 'fmDragBehaviorDisabled 
 
 ToggleButton4.Value = False 
 ToggleButton4.Caption = "Select All" 
 ToggleButton4.WordWrap = True 
 TextBox2.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll 
End Sub 
 
Sub ToggleButton1_Click() 
 If ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "Drag Enabled" 
 TextBox1.DragBehavior = 1 'fmDragBehaviorEnabled 
 Else 
 ToggleButton1.Caption = "Drag Disabled" 
 TextBox1.DragBehavior = 0 'fmDragBehaviorDisabled 
 End If 
End Sub 
 
Sub ToggleButton2_Click() 
 If ToggleButton2.Value = True Then 
 ToggleButton2.Caption = "Recall Selection" 
 TextBox1.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection 
 Else 
 ToggleButton2.Caption = "Select All" 
 TextBox1.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll 
 End If 
End Sub 
 
Sub ToggleButton3_Click() 
 If ToggleButton3.Value = True Then 
 ToggleButton3.Caption = "Drag Enabled" 
 TextBox2.DragBehavior = 1 'fmDragBehaviorEnabled 
 Else 
 ToggleButton3.Caption = "Drag Disabled" 
 TextBox2.DragBehavior = 0 'fmDragBehaviorDisabled 
 End If 
End Sub 
 
Sub ToggleButton4_Click() 
 If ToggleButton4.Value = True Then 
 ToggleButton4.Caption = "Recall Selection" 
 TextBox2.EnterFieldBehavior = 1 'fmEnterFieldBehaviorRecallSelection 
 Else 
 ToggleButton4.Caption = "Select All" 
 TextBox2.EnterFieldBehavior = 0 'fmEnterFieldBehaviorSelectAll 
 End If 
End Sub

支持和反馈

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