DragBehavior 和 EnterFieldBehavior 属性示例
下例用 DragBehavior 和 EnterFieldBehavior 属性,演示当进入控件并把信息从一个控件拖入另一控件时可提供的不同效果。
该示例使用两个文本框控件。可以给每个控件设置 DragBehavior 和 EnterFieldBehavior 并查看从一个控件到另一控件的拖动效果。
窗体包含:
- 名为 TextBox1 的文本框。
- 名为 ToggleButton1 和 ToggleButton2 的两个切换按钮控件。这些控件与 TextBox1 相关联。
- 名为 TextBox2 的文本框。
- 名为 ToggleButton3 和 ToggleButton4 的两个切换按钮控件。这些控件与 TextBox2 相关联。
Sub UserForm_Initialize()
UserForm_TextBox1.Text = "Once upon a time in a land ...,"
UserForm_ToggleButton1.Value = True
UserForm_ToggleButton1.Caption = "Drag Enabled"
UserForm_ToggleButton1.WordWrap = True
UserForm_TextBox1.DragBehavior = 1
UserForm_ToggleButton2.Value = True
UserForm_ToggleButton2.Caption = "Recall Selection"
UserForm_ToggleButton2.WordWrap = True
UserForm_TextBox1.EnterFieldBehavior = 1
UserForm_TextBox2.Text = "XXX, YYYY"
UserForm_ToggleButton3.Value = False
UserForm_ToggleButton3.Caption = "Drag Disabled"
UserForm_ToggleButton3.WordWrap = True
UserForm_TextBox2.DragBehavior = 0
UserForm_ToggleButton4.Value = False
UserForm_ToggleButton4.Caption = "Select All"
UserForm_ToggleButton4.WordWrap = True
UserForm_TextBox2.EnterFieldBehavior = 0
End Sub
Sub UserForm_ToggleButton1_Click()
If UserForm_ToggleButton1.Value = True Then
UserForm_ToggleButton1.Caption = "Drag Enabled"
UserForm_TextBox1.DragBehavior = 1
Else
UserForm_ToggleButton1.Caption = "Drag Disabled"
UserForm_TextBox1.DragBehavior = 0
End If
End Sub
Sub UserForm_ToggleButton2_Click()
If UserForm_ToggleButton2.Value = True Then
UserForm_ToggleButton2.Caption = "Recall Selection"
UserForm_TextBox1.EnterFieldBehavior = 1
Else
UserForm_ToggleButton2.Caption = "Select All"
UserForm_TextBox1.EnterFieldBehavior = 0
End If
End Sub
Sub UserForm_ToggleButton3_Click()
If UserForm_ToggleButton3.Value = True Then
UserForm_ToggleButton3.Caption = "Drag Enabled"
UserForm_TextBox2.DragBehavior = 1
Else
UserForm_ToggleButton3.Caption = "Drag Disabled"
UserForm_TextBox2.DragBehavior = 0
End If
End Sub
Sub UserForm_ToggleButton4_Click()
If UserForm_ToggleButton4.Value = True Then
UserForm_ToggleButton4.Caption = "Recall Selection"
UserForm_TextBox2.EnterFieldBehavior = 1
Else
UserForm_ToggleButton4.Caption = "Select All"
UserForm_TextBox2.EnterFieldBehavior = 0
End If
End Sub
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64