DblClick 事件、CanPaste 属性、Paste 和 Copy 方法示例DblClick event, CanPaste property, Paste, Copy methods example

下面的示例使用**CanPaste** 属性和**paste** 方法将一个**ComboBox** 从剪贴板粘贴到******页页面** 上的页面。The following example uses the CanPaste property and the Paste method to paste a ComboBox from the Clipboard to a Page of a MultiPage.

此示例还使用**SetFocus** 和**copy** 方法将控件从窗体复制到剪贴板。This sample also uses the SetFocus and Copy methods to copy a control from the form to the Clipboard.

用户单击 CommandButton1 可将 ComboBox 复制到剪贴板。The user clicks CommandButton1 to copy the ComboBox to the Clipboard. 用户双击(使用 DblClick 事件)CommandButton1 可将 ComboBox 粘贴到 MultiPageThe user double-clicks (using the DblClick event) CommandButton1 to paste the ComboBox to the MultiPage.

若要使用此示例,请将此示例代码复制到窗体的 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.
  • 名为 ComboBox1 的 ComboBoxA ComboBox named ComboBox1.
  • 名为 MultiPage1 的 MultiPageA MultiPage named MultiPage1.
  • 一个名为"CommandButton1"的 CommandButtonA CommandButton named CommandButton1.


[!注释] 此示例还包括一个子例程来说明如何将文本粘贴到控件。This example also includes a subroutine to illustrate pasting text into a control.

Private Sub UserForm_Initialize() 
 ComboBox1.AddItem "It's a beautiful day!" 
 CommandButton1.Caption = "Copy ComboBox to " _ 
 & "Clipboard" 
 CommandButton1.AutoSize = True 
End Sub 
Private Sub MultiPage1_DblClick(ByVal Index As Long, _ 
 ByVal Cancel As MSForms.ReturnBoolean) 
 If MultiPage1.Pages(MultiPage1.Value).CanPaste = _ 
 TextBox1.Text = "Can't Paste" 
 End If 
End Sub 
Private Sub CommandButton1_Click() 
End Sub 
'Code for pasting text into a control 
'Private Sub ComboBox1_DblClick(ByVal Cancel As _ 
' If ComboBox1.CanPaste = True Then 
' ComboBox1.Paste 
' Else 
' TextBox1.Text = "Can't Paste" 
' 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.