DragBehavior、EnterFieldBehavior 属性示例DragBehavior, EnterFieldBehavior properties example

下面的示例使用**DragBehavior** 和**EnterFieldBehavior** 属性演示在输入控件时可以提供的不同效果, 以及将信息从一个控件拖到另一个控件时。The following example uses the DragBehavior and EnterFieldBehavior properties to demonstrate the different effects that you can provide when entering a control and when dragging information from one control to another.

该示例使用两个**TextBox** 控件。The sample uses two TextBox controls. 您可以为每个控件设置 DragBehaviorEnterFieldBehavior ,并查看从一个控件拖曳到另一个控件的效果。You can set DragBehavior and EnterFieldBehavior for each control and see the effects of dragging from one control to another.

若要使用此示例,请将此示例代码复制到窗体的 Declarations 部分。To use this example, copy this sample code to the Declarations portion of a form. 确保该窗体包含:Make sure that the form contains:

  • 一个名为"TextBox1"的 TextBoxA TextBox named TextBox1.
  • 两个名称分别为"ToggleButton1"和"ToggleButton2"的 ToggleButton 控件。Two ToggleButton controls named ToggleButton1 and ToggleButton2. 这些控件与 TextBox1 相关。These controls are associated with TextBox1.
  • 一个名为"TextBox2"的 TextBoxA TextBox named TextBox2.
  • 两个名称分别为"ToggleButton3"和"ToggleButton4"的 ToggleButton 控件。Two ToggleButton controls named ToggleButton3 and ToggleButton4. 这些控件和"TextBox2"相关。These controls are associated with TextBox2.
Private Sub UserForm_Initialize() 
 TextBox1.Text = "Once upon a time in a land ...," 
 ToggleButton1.Value = True 
 ToggleButton1.Caption = "Drag Enabled" 
 ToggleButton1.WordWrap = True 
 TextBox1.DragBehavior = fmDragBehaviorEnabled 
 
 ToggleButton2.Value = True 
 ToggleButton2.Caption = "Recall Selection" 
 ToggleButton2.WordWrap = True 
 TextBox1.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorRecallSelection 
 
 TextBox2.Text = "XXX, YYYY" 
 ToggleButton3.Value = False 
 ToggleButton3.Caption = "Drag Disabled" 
 ToggleButton3.WordWrap = True 
 TextBox2.DragBehavior = fmDragBehaviorDisabled 
 
 ToggleButton4.Value = False 
 ToggleButton4.Caption = "Select All" 
 ToggleButton4.WordWrap = True 
 TextBox2.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorSelectAll 
End Sub 
 
Private Sub ToggleButton1_Click() 
 If ToggleButton1.Value = True Then 
 ToggleButton1.Caption = "Drag Enabled" 
 TextBox1.DragBehavior = fmDragBehaviorEnabled 
 Else 
 ToggleButton1.Caption = "Drag Disabled" 
 TextBox1.DragBehavior = fmDragBehaviorDisabled 
 End If 
End Sub 
 
Private Sub ToggleButton2_Click() 
 If ToggleButton2.Value = True Then 
 ToggleButton2.Caption = "Recall Selection" 
 TextBox1.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorRecallSelection 
 Else 
 ToggleButton2.Caption = "Select All" 
 TextBox1.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorSelectAll 
 End If 
End Sub 
 
Private Sub ToggleButton3_Click() 
 If ToggleButton3.Value = True Then 
 ToggleButton3.Caption = "Drag Enabled" 
 TextBox2.DragBehavior = fmDragBehaviorEnabled 
 Else 
 ToggleButton3.Caption = "Drag Disabled" 
 TextBox2.DragBehavior = fmDragBehaviorDisabled 
 End If 
End Sub 
 
Private Sub ToggleButton4_Click() 
 If ToggleButton4.Value = True Then 
 ToggleButton4.Caption = "Recall Selection" 
 TextBox2.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorRecallSelection 
 Else 
 ToggleButton4.Caption = "Select All" 
 TextBox2.EnterFieldBehavior = _ 
 fmEnterFieldBehaviorSelectAll 
 End If 
End Sub

支持和反馈Support and feedback

有关于 Office VBA 或本文档的疑问或反馈?Have questions or feedback about Office VBA or this documentation? 请参阅 Office VBA 支持和反馈,获取有关如何接收支持和提供反馈的指南。Please see Office VBA support and feedback for guidance about the ways you can receive support and provide feedback.