Copy, GetFromClipboard, GetText Methods, DataObject Object Example
The following example demonstrates data movement from a TextBox to the Clipboard, from the Clipboard to a DataObject, and from a DataObject into another TextBox. The GetFromClipboard method transfers the data from the Clipboard to a DataObject. The Copy and GetText methods are also used.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:
- Two TextBox controls named TextBox1 and TextBox2.
- A CommandButton named CommandButton1.
- Код: Выделить всё
Dim MyData as DataObject
Private Sub CommandButton1_Click()
'Need to select text before copying it to Clipboard
TextBox1.SelStart = 0
TextBox1.SelLength = TextBox1.TextLength
TextBox1.Copy
MyData.GetFromClipboard
TextBox2.Text = MyData.GetText(1)
End Sub
Private Sub UserForm_Initialize()
Set MyData = New DataObject
TextBox1.Text = "Move this data to the " _
& "Clipboard, to a DataObject, then to "
& "TextBox2!"
End Sub
Paste, PutInClipboard, SetText Methods Example
The following example demonstrates data movement from a TextBox to a DataObject, from a DataObject to the Clipboard, and from the Clipboard to another TextBox. The PutInClipboard method transfers the data from a DataObject to the Clipboard. The SetText and Paste methods are also used.
To use this example, copy this sample code to the Declarations portion of a form. Make sure that the form contains:
- Two TextBox controls named TextBox1 and TextBox2.
- A CommandButton named CommandButton1.
- Код: Выделить всё
Dim MyData As DataObject
Private Sub CommandButton1_Click()
Set MyData = New DataObject
MyData.SetText TextBox1.Text
MyData.PutInClipboard
TextBox2.Paste
End Sub
Private Sub UserForm_Initialize()
TextBox1.Text = "Move this data to a " _
& "DataObject, to the Clipboard, then to " _
& "TextBox2!"
End Sub
Сейчас этот форум просматривают: нет зарегистрированных пользователей и гости: 86