Add、Cut、Paste 方法,Page 对象和多页控件示例

下例用 Add、Cut 和 Paste 方法从多页控件的页中剪切和粘贴控件。剪切和粘贴操作中涉及的控件,动态地被添加进窗体。

本示例假设用户将添加,然后剪切、粘贴新的控件。

窗体包含:

  • 名为从 CommandButton1 到 CommandButton3 的三个命令按钮控件。
  • 名为 Multipage1 的多页控件。
Dim MyTextBox

Sub UserForm_CommandButton1_Click()
    Set MyTextBox = UserForm_MultiPage1.Pages(0).Controls.Add("Forms.TextBox.1", "MyTextBox", Visible)
    UserForm_CommandButton2.Enabled = True
    UserForm_CommandButton1.Enabled = False
End Sub

Sub UserForm_CommandButton2_Click()
    UserForm_MultiPage1.Pages(0).Controls.Cut
    UserForm_CommandButton3.Enabled = True
    UserForm_CommandButton2.Enabled = False
End Sub

Sub UserForm_CommandButton3_Click()
    Dim MyPage
    Set MyPage = UserForm_MultiPage1.Pages.Item(0)
    
    MyPage.Paste
    UserForm_CommandButton3.Enabled = False
End Sub

Sub UserForm_Initialize()
    UserForm_CommandButton1.Caption = "Add"
    UserForm_CommandButton2.Caption = "Cut"
    UserForm_CommandButton3.Caption = "Paste"
    
    UserForm_CommandButton1.Enabled = True
    UserForm_CommandButton2.Enabled = False
    UserForm_CommandButton3.Enabled = False
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