Breyta

Deila með


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
Clipboard

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()

Clears any data from the system Clipboard.

ContainsAudio()

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

ContainsData(String)

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

ContainsFileDropList()

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

ContainsImage()

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

ContainsText()

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

ContainsText(TextDataFormat)

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

Flush()

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

GetAudioStream()

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

GetData(String)

Retrieves data in a specified format from the Clipboard.

GetDataObject()

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

GetFileDropList()

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

GetImage()

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

GetText()

Returns a string containing the UnicodeText data on the Clipboard.

GetText(TextDataFormat)

Returns a string containing text data on the Clipboard.

IsCurrent(IDataObject)

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

SetAudio(Byte[])

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

SetAudio(Stream)

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

SetData(String, Object)

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

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.

SetDataObject(Object)

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

SetFileDropList(StringCollection)

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

SetImage(BitmapSource)

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

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.

SetText(String)

Stores UnicodeText data on the Clipboard.

Applies to

See also