Browse DevX
Sign up for e-mail newsletters from DevX

Tip of the Day
Language: VBNET
Expertise: beginner
Mar 2, 2002



Building the Right Environment to Support AI, Machine Learning and Deep Learning

Copying data into the Clipboard

Copying a piece of information into the clipboard is as easy as calling the Clipboard.SetDataObject: you can pass this method a string, an image, and so on. If you pass it a string that contains text in Rich Text Format (RTF), the Clipboard object detects this format automatically. For example, the following procedure copies the selected portion of a TextBox control (or the entire control's contents, if no text is selected) into the clipboard:

Sub CopyFromTextBox(ByVal tb As TextBox)
    ' Copy the TextBox's selected text to the clipboard.
    Dim t As String = tb.SelectedText
    ' Copy the entire Text, if no text is selected.
    If t.Length = 0 Then t = tb.Text
    ' Proceed only if there is something to be copied.
    If t.Length > 0 Then
    End If
End Sub
The SetDataObject can take a second argument, which you should set to True if you want to make the copied object available after the current program terminates:

        ' Make the copied text available after the application ends.
        Clipboard.SetDataObject(t, True)
Remember that you can put any object in the clipboard, including objects that are private to your application and that shouldn't be accessed by other programs.
Francesco Balena
Comment and Contribute






(Maximum characters: 1200). You have 1200 characters left.



Thanks for your registration, follow us on our social networks to keep up-to-date