Accessing the Clipboard
The Clipboard class is used to get or add data to the system-wide clipboard. The properties and methods let you determine what kind of data is available on the Clipboard, get data from the Clipboard, and send data to the Clipboard. The Clipboard class supports three kinds of data: text, picture, and binary/raw data. Raw data is represented in string form and is marked with a type you specify so you can tell what the raw binary data represents.
Text
Getting text from the Clipboard
Since the Clipboard can contain text, picture and binary data, you should ask it what type of data it contains before you attempt to use it. To check for text, you use the TextAvailable method:
Var c As New Clipboard
Var clipText As String
If c.TextAvailable Then
clipText = c.Text
End If
c.Close
Adding text to the Clipboard
This code adds text to the clipboard:
Var c As Clipboard
c.Text = "Hello!"
c.Close
Pictures
The clipboard can contain any picture that can be stored in the Picture class.
Getting a picture from the Clipboard
Since the Clipboard can contain text, picture and binary data, you should ask it what type of data it contains before you attempt to use it. To check for a picture, you use the PictureAvailable method:
Var c As New Clipboard
Var clipPic As Picture
If c.PictureAvailable Then
clipPic = c.Picture
End If
c.Close
Adding a picture to the Clipboard
This code adds a picture to the clipboard:
Var c As New Clipboard
c.Picture = ImageWell.Image
c.Close
Raw data
Raw data refers to any data that is not text or is not a picture. This allows you to put any type of data you want in the clipboard. Only your own apps will be able to parse custom data you put here, however. When you put data in the clipboard you can specify the data type using a UTI. Standard UTIs, such as "public.rtf" may be readable by other apps if your data is formatted properly.
Getting raw data from the Clipboard
Use the RawData method to get raw data from the Clipboard. The raw data is in string format and you supply a type indicator used to identify the type of data being fetched.
This code gets RTF data from the Clipboard and stores it in a Text Area:
Var c As New Clipboard
If c.RawDataAvailable("public.rtf") Then
TextArea1.StyledText.RTFData = c.RawData("public.rtf")
End If
c.Close
Adding raw data from the Clipboard
Use the AddRawData method to add raw data to the clipboard, specifying the type.
This code stores the RTF data from a styled Text Area in the Clipboard so that other apps should be able to read it:
Var c As New Clipboard
c.AddRawData(TextArea1.StyledText.RTFData, "public.rtf")
c.Close