Class

# Clipboard

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

## Description

Used to read and write information to and from the <span class="title-ref">Clipboard</span>.

## Properties

<div class="rst-class">

table-centered_columns_3_and_4

</div>

| Name                         | Type                             | Read-Only | Shared |
|------------------------------|----------------------------------|-----------|--------|
| `Picture<clipboard.picture>` | `Picture</api/graphics/picture>` |           |        |
| `Text<clipboard.text>`       | `String</api/data_types/string>` |           |        |

## Methods

<div class="rst-class">

table-centered_column_4

</div>

| Name                                           | Parameters                                                                                                               | Returns                            | Shared |
|------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------|------------------------------------|--------|
| `Close<clipboard.close>`                       |                                                                                                                          |                                    |        |
| `PictureAvailable<clipboard.pictureavailable>` |                                                                                                                          | `Boolean</api/data_types/boolean>` |        |
| `RawData<clipboard.rawdata>`                   | dataType As `String</api/data_types/string>`                                                                             | `String</api/data_types/string>`   |        |
| `RawData<clipboard.rawdata>`                   | dataType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>` |                                    |        |
| `RawDataAvailable<clipboard.rawdataavailable>` | dataType As `String</api/data_types/string>`                                                                             | `Boolean</api/data_types/boolean>` |        |
| `TextAvailable<clipboard.textavailable>`       |                                                                                                                          | `Boolean</api/data_types/boolean>` |        |

## Property descriptions

<div id="clipboard.picture">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.Picture

**Picture** As `Picture</api/graphics/picture>`

> The picture on the <span class="title-ref">Clipboard</span>.
>
> This code is in the Pressed event of a button. It tests whether a picture is on the <span class="title-ref">Clipboard</span>. If so, it assigns it to the Backdrop property of the `Canvas</api/user_interface/desktop/desktopcanvas>`. This causes the picture to appear in the control. It will be cropped to the size of the `Canvas</api/user_interface/desktop/desktopcanvas>`.
>
> ``` xojo
> 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
> ```

<div id="clipboard.text">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.Text

**Text** As `String</api/data_types/string>`

> The text on the <span class="title-ref">Clipboard</span>.
>
> On macOS, if you need to change the Text in the <span class="title-ref">Clipboard</span> after you have set it, you should create a new <span class="title-ref">Clipboard</span> object first.
>
> This code is in the Pressed event of a button. It checks the <span class="title-ref">Clipboard</span> for text. If it finds text, it assigns it to the Text property of the `DesktopTextField</api/user_interface/desktop/desktoptextfield>`.
>
> ``` xojo
> 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

<div id="clipboard.close">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.Close

**Close**

> Closes the <span class="title-ref">Clipboard</span> which enables other <span class="title-ref">Clipboard</span> objects or other programs to access the <span class="title-ref">Clipboard</span>'s data. This function only affects Windows and is automatically called by the <span class="title-ref">Clipboard</span>'s Destructor.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for iOS.
>
> </div>
>
> This code gets the text on the <span class="title-ref">Clipboard</span> and copies it to a variable.
>
> ``` xojo
> Var c As New Clipboard
> Var s As String = c.Text
> c.Close
> ```

<div id="clipboard.pictureavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.PictureAvailable

**PictureAvailable** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">Clipboard</span> contains a picture.
>
> The following code is in the Presssed event of a button. If a picture is on the <span class="title-ref">Clipboard</span>, it assigns it to the Backdrop property of a `Canvas</api/user_interface/desktop/desktopcanvas>`. The result is that the picture appears immediately.
>
> ``` xojo
> 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
> ```

<div id="clipboard.rawdata">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.RawData

**RawData**(dataType As `String</api/data_types/string>`) As `String</api/data_types/string>`

**RawData**(dataType As `String</api/data_types/string>`, `Assigns</api/language/assigns>` value As `String</api/data_types/string>`)

> Used to get and set binary data from/to the <span class="title-ref">Clipboard</span> as a `string</api/data_types/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"](http://msdn.microsoft.com/en-us/library/aa767917(v=vs.85).aspx) to add or fetch HTML data from the <span class="title-ref">Clipboard</span>.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for iOS and Android.
>
> </div>
>
> This code reads the contents of the <span class="title-ref">Clipboard</span> as an mp3 file.
>
> ``` xojo
> 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\`:
>
> ``` xojo
> 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 <span class="title-ref">Clipboard</span>. It contains RTF text:
>
> ``` xojo
> Var c As New Clipboard
> c.RawData("public.rtf") = TextArea1.Text
> c.Close
> ```

<div id="clipboard.rawdataavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.RawDataAvailable

**RawDataAvailable**(dataType As `String</api/data_types/string>`) As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the <span class="title-ref">Clipboard</span> 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](http://msdn.microsoft.com/en-us/library/aa767917(v=vs.85).aspx) from the <span class="title-ref">Clipboard</span>.
>
> <div class="important">
>
> <div class="title">
>
> Important
>
> </div>
>
> This method is not supported for iOS and Android.
>
> </div>
>
> The following code checks the RawDataAvailable flag prior to reading the contents of the <span class="title-ref">Clipboard</span>.
>
> ``` xojo
> If c.RawDataAvailable("public.text") Then
>   TextField1.Text = c.RawData("public.text")
> End If
>
> c.Close
> ```

<div id="clipboard.textavailable">

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

</div>

<div class="rst-class">

forsearch

</div>

Clipboard.TextAvailable

**TextAvailable** As `Boolean</api/data_types/boolean>`

> Returns `True</api/language/true>` if the data on the <span class="title-ref">Clipboard</span> is text.
>
> This code is in the Pressed event of a button. It checks the <span class="title-ref">Clipboard</span> for text. If it finds text, it assigns it to the Text property of the `DesktopTextField</api/user_interface/desktop/desktoptextfield>`.
>
> ``` xojo
> 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 <span class="title-ref">Clipboard</span>, you must create an object of type <span class="title-ref">Clipboard</span> and then access the Text or Picture properties of the <span class="title-ref">Clipboard</span> object you create. You can place a picture on the <span class="title-ref">Clipboard</span> by setting the Picture property. You can use the SetText and AddRawData methods to write text or binary data to the <span class="title-ref">Clipboard</span>. The <span class="title-ref">Clipboard</span> class is not available to Console applications.

For best results, create a new <span class="title-ref">Clipboard</span> object each time you need to use the <span class="title-ref">Clipboard</span>.

The <span class="title-ref">Clipboard</span> supports `UTIs \(Uniform Type Identifiers\)</topics/file_management/understanding_uniform_type_identifiers>`.

## Sample code

This code gets the text on the <span class="title-ref">Clipboard</span> and copies it to a variable:

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code puts text on the \`Clipboard\`:

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

This code checks to see if the <span class="title-ref">Clipboard</span> is text data and if so, copies the contents of the <span class="title-ref">Clipboard</span> to a `TextField</api/user_interface/desktop/desktoptextfield>`:

``` xojo
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\`:

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

---------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------

When you want to put more than one item on the <span class="title-ref">Clipboard</span>, 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:

``` xojo
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

|                       |                 |
|-----------------------|-----------------|
| **Project Types**     | Desktop, Mobile |
| **Operating Systems** | All             |
