Clipboard Clipboard Clipboard Clipboard Class

Definition

Provides static methods that facilitate transferring data to and from the system Clipboard.

public ref class Clipboard abstract sealed
public static class Clipboard
type Clipboard = class
Public Class Clipboard
Inheritance
ClipboardClipboardClipboardClipboard

Examples

The following example shows how to add data to the system Clipboard.


// For this example, the data to be placed on the clipboard is a simple
// string.
string textData = "I want to put this string on the clipboard.";

// After this call, the data (string) is placed on the clipboard and tagged
// with a data format of "Text".
Clipboard.SetData(DataFormats.Text, (Object)textData);
' For this example, the data to be placed on the clipboard is a simple
' string.
Dim textData As String = "I want to put this string on the clipboard."

' After this call, the data (string) is placed on the clipboard and tagged
' with a data format of "Text".
Clipboard.SetData(DataFormats.Text, CType(textData, Object))

Remarks

All applications for Windows share the system Clipboard, so the contents are subject to change when you switch to another application.

For a list of predefined formats available to use with the Clipboard class, see the DataFormats class.

Security Alert: For security purposes, the following points should be kept in mind.

  • Paste operations need to be user initiated (Ctrl-V, Paste Menu).

  • Copy can only be on user selected content.

  • On copy or cut, partial trust code puts plaintext and Extensible Application Markup Language (XAML) on to the clipboard. Plaintext includes text, Unicode text, OEM (Object Exchange Model) text, and CSV (Comma-separated values).

  • On paste, Windows Presentation Foundation (WPF) will paste in Extensible Application Markup Language (XAML) if the source of that content is from a equally trusted or more trusted site. Specifically:

    • A partial trust application can paste Extensible Application Markup Language (XAML) from a full trust application.

    • A partial trust application can paste Extensible Application Markup Language (XAML) from a partial trust application.

    • A full trust application can paste XAML only from another fully trusted application.

    • A non-Windows Presentation Foundation (WPF) full trust application can examine the ApplicationTrust format on the clipboard and sanitize the XAML if appropriate.

Methods

Clear() Clear() Clear() Clear()

Clears any data from the system Clipboard.

ContainsAudio() ContainsAudio() ContainsAudio() ContainsAudio()

Queries the Clipboard for the presence of data in the WaveAudio data format.

ContainsData(String) ContainsData(String) ContainsData(String) ContainsData(String)

Queries the Clipboard for the presence of data in a specified data format.

ContainsFileDropList() ContainsFileDropList() ContainsFileDropList() ContainsFileDropList()

Queries the Clipboard for the presence of data in the FileDrop data format.

ContainsImage() ContainsImage() ContainsImage() ContainsImage()

Queries the Clipboard for the presence of data in the Bitmap data format.

ContainsText() ContainsText() ContainsText() ContainsText()

Queries the Clipboard for the presence of data in the UnicodeText format.

ContainsText(TextDataFormat) ContainsText(TextDataFormat) ContainsText(TextDataFormat) ContainsText(TextDataFormat)

Queries the Clipboard for the presence of data in a text data format.

Flush() Flush() Flush() Flush()

Permanently adds the data that is on the Clipboard so that it is available after the data's original application closes.

GetAudioStream() GetAudioStream() GetAudioStream() GetAudioStream()

Returns a stream of Clipboard data in the WaveAudio data format.

GetData(String) GetData(String) GetData(String) GetData(String)

Retrieves data in a specified format from the Clipboard.

GetDataObject() GetDataObject() GetDataObject() GetDataObject()

Returns a data object that represents the entire contents of the Clipboard.

GetFileDropList() GetFileDropList() GetFileDropList() GetFileDropList()

Returns a string collection that contains a list of dropped files available on the Clipboard.

GetImage() GetImage() GetImage() GetImage()

Returns a BitmapSource object from the Clipboard that contains data in the Bitmap format.

GetText() GetText() GetText() GetText()

Returns a string containing the UnicodeText data on the Clipboard.

GetText(TextDataFormat) GetText(TextDataFormat) GetText(TextDataFormat) GetText(TextDataFormat)

Returns a string containing text data on the Clipboard.

IsCurrent(IDataObject) IsCurrent(IDataObject) IsCurrent(IDataObject) IsCurrent(IDataObject)

Compares a specified data object to the contents of the Clipboard.

SetAudio(Byte[]) SetAudio(Byte[]) SetAudio(Byte[]) SetAudio(Byte[])

Stores audio data (WaveAudio data format) on the Clipboard. The audio data is specified as a byte array.

SetAudio(Stream) SetAudio(Stream) SetAudio(Stream) SetAudio(Stream)

Stores audio data (WaveAudio data format) on the Clipboard. The audio data is specified as a stream.

SetData(String, Object) SetData(String, Object) SetData(String, Object) SetData(String, Object)

Stores the specified data on the Clipboard in the specified format.

SetDataObject(Object) SetDataObject(Object) SetDataObject(Object) SetDataObject(Object)

Places a specified non-persistent data object on the system Clipboard.

SetDataObject(Object, Boolean) SetDataObject(Object, Boolean) SetDataObject(Object, Boolean) SetDataObject(Object, Boolean)

Places a specified data object on the system Clipboard and accepts a Boolean parameter that indicates whether the data object should be left on the Clipboard when the application exits.

SetFileDropList(StringCollection) SetFileDropList(StringCollection) SetFileDropList(StringCollection) SetFileDropList(StringCollection)

Stores FileDrop data on the Clipboard. The dropped file list is specified as a string collection.

SetImage(BitmapSource) SetImage(BitmapSource) SetImage(BitmapSource) SetImage(BitmapSource)

Stores Bitmap data on the Clipboard. The image data is specified as a BitmapSource.

SetText(String) SetText(String) SetText(String) SetText(String)

Stores UnicodeText data on the Clipboard.

SetText(String, TextDataFormat) SetText(String, TextDataFormat) SetText(String, TextDataFormat) SetText(String, TextDataFormat)

Stores text data on the Clipboard in a specified text data format. The UnicodeText data to store is specified as a string.

Applies to

See Also