Class

Clipboard


Description

Used to read and write information to and from the Clipboard.

Properties

Name

Type

Read-Only

Shared

Picture

Picture

Text

String

Methods

Name

Parameters

Returns

Shared

Close

PictureAvailable

Boolean

RawData

DataType As String

String

RawDataAvailable

DataType As String

Boolean

TextAvailable

Boolean

Property descriptions


Clipboard.Picture

Picture As Picture

The picture on the Clipboard.

This code is in the Action event of a button. It tests whether a picture is on the Clipboard. If so, it assigns it to the Backdrop property of the Canvas. This causes the picture to appear in the control. It will be cropped to the size of the Canvas.

Var c As Clipboard

// create a new instance of the clipboard
c = New Clipboard

// check to see if a picture is available
If c.PictureAvailable Then
  Var myPicture As Picture
  myPicture = c.Picture // get the picture
  Canvas1.Backdrop = myPicture // set the backdrop
End If

// close the clipboard
c.Close

Clipboard.Text

Text As String

The text on the Clipboard.

On macOS, if you need to change the Text in the Clipboard after you have set it, you should create a new Clipboard object first.

This code is in the Pressed event of a button. It checks the Clipboard for text. If it finds text, it assigns it to the Text property of the DesktopTextField.

Var c As Clipboard

// create an instance of the clipboard
c = New Clipboard

// check for textAvailable
If c.TextAvailable Then
  // text is available, set the TextField to it
  TextField1.Text = c.Text
End If

// close it
c.Close

Method descriptions


Clipboard.Close

Close

Closes the Clipboard which enables other Clipboard objects or other programs to access the Clipboard's data. This function only affects Windows and is automatically called by the Clipboard's Destructor.

This code gets the text on the Clipboard and copies it to a variable.

Var c As New Clipboard
Var s As String = c.Text
c.Close

Clipboard.PictureAvailable

PictureAvailable As Boolean

Returns True if the Clipboard contains a picture.

The following code is in the Presssed event of a button. If a picture is on the Clipboard, it assigns it to the Backdrop property of a Canvas. The result is that the picture appears immediately.

Var c As Clipboard

// create a new instance of the clipboard
c = New Clipboard

// check to see if a picture is available
If c.PictureAvailable Then
  Var myPicture As Picture
  myPicture = c.Picture // get the picture
  Canvas1.Backdrop = myPicture // set the backdrop
End If

// close the clipboard
c.Close

Clipboard.RawData

RawData(DataType As String) As String

Used to get and set binary data from/to the Clipboard as a string for the specified type or UTI.

The DataType parameter supports both the older MacType and newer UTIs. If the DataType parameter is exactly 4 bytes then it is treated as a MacType for backwards compatibility. Otherwise it is treated as a UTI. An example would be "public.rtf".

On Windows you can use the a special DataType called "HTML Format" to add or fetch HTML data from the Clipboard.

Important

This method is not supported for iOS.

This code reads the contents of the Clipbpoard as an mp3 file.

Var c As New Clipboard
Var s As String
s = c.RawData("public.mp3") // UTI
c.Close

On Windows, this code gets HTML data from the Clipboard:

Var c As New Clipboard
Var html As String
html = c.RawData("HTML Format")
c.Close

The following code places the contents of TextArea1 on the Clipboard. It contains RTF text:

Var c As New Clipboard
c.RawData("public.rtf") = TextArea1.Text
c.Close

Clipboard.RawDataAvailable

RawDataAvailable(DataType As String) As Boolean

Returns True if the Clipboard contains data.

The DataType parameter supports both the older MacType and newer UTIs. If the DataType parameter is exactly 4 bytes then it is treated as a MacType for backwards compatibility. Otherwise it is treated as a UTI.

On Windows you can use the a special DataType called "HTML Format" to add or fetch HTML data from the Clipboard.

Important

This method is not supported for iOS.

The following code checks the RawDataAvailable flag prior to reading the contents of the Clipboard.

If c.RawDataAvailable("public.text") Then
  TextField1.Text = c.RawData("public.text")
End If
c.Close

Clipboard.TextAvailable

TextAvailable As Boolean

Returns True if the data on the Clipboard is text.

This code is in the Pressed event of a button. It checks the Clipboard for text. If it finds text, it assigns it to the Text property of the DesktopTextField.

Var c As Clipboard

// create an instance of the clipboard
c = New Clipboard

// check for textAvailable
If c.TextAvailable Then
  // text is available, set the TextField to it
  TextField1.Text = c.Text
End If

// close it
c.Close

Notes

In order to read text from or write text to the Clipboard, you must create an object of type Clipboard and then access the Text or Picture properties of the Clipboard object you create. You can place a picture on the Clipboard by setting the Picture property. You can use the SetText and AddRawData methods to write text or binary data to the Clipboard. The Clipboard class is not available to Console applications.

For best results, create a new Clipboard object each time you need to use the Clipboard.

The Clipboard supports UTIs (Uniform Type Identifiers).

Sample code

This code gets the text on the Clipboard and copies it to a variable:

Var c As New Clipboard
Var s As String
s = c.Text
c.Close

This code puts text on the Clipboard:

Var c As New Clipboard
c.Text = "The Quick Brown Fox outran the Lazy Dog"
c.Close

This code checks to see if the Clipboard is text data and if so, copies the contents of the Clipboard to a TextField:

Var c As New Clipboard
If c.TextAvailable Then
  TextField1.Text = c.Text
End If
c.Close

This code copies an image to the Clipboard:

Var c As New Clipboard
If ImageWell1.Image <> Nil Then
  c.Picture = ImageWell1.Image
  c.Close
Else
  MessageBox("No picture is available!")
End If

When you want to put more than one item on the Clipboard, you can't use the properties of this class to append new text or graphics to existing material. You need to do the appending in your code and just use one call to the Text property:

Var text1 As String = "This is the first item being put on the clipboard!"
Var text2 As String = "This is the second item being put on the clipboard"
Var c As New Clipboard
c.Text = text1 + text2
c.Close

Compatibility

All project types on all supported operating systems.