Clipboard Class
TOC
Collapse the table of content
Expand the table of content

Clipboard Class

 

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

Namespace:   System.Windows
Assembly:  PresentationCore (in PresentationCore.dll)

System.Object
  System.Windows.Clipboard

public static class Clipboard

NameDescription
System_CAPS_pubmethodSystem_CAPS_staticClear()

Clears any data from the system Clipboard.

System_CAPS_pubmethodSystem_CAPS_staticContainsAudio()

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

System_CAPS_pubmethodSystem_CAPS_staticContainsData(String)

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

System_CAPS_pubmethodSystem_CAPS_staticContainsFileDropList()

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

System_CAPS_pubmethodSystem_CAPS_staticContainsImage()

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

System_CAPS_pubmethodSystem_CAPS_staticContainsText()

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

System_CAPS_pubmethodSystem_CAPS_staticContainsText(TextDataFormat)

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

System_CAPS_pubmethodSystem_CAPS_staticFlush()

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

System_CAPS_pubmethodSystem_CAPS_staticGetAudioStream()

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

System_CAPS_pubmethodSystem_CAPS_staticGetData(String)

Retrieves data in a specified format from the Clipboard.

System_CAPS_pubmethodSystem_CAPS_staticGetDataObject()

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

System_CAPS_pubmethodSystem_CAPS_staticGetFileDropList()

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

System_CAPS_pubmethodSystem_CAPS_staticGetImage()

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

System_CAPS_pubmethodSystem_CAPS_staticGetText()

Returns a string containing the UnicodeText data on the Clipboard.

System_CAPS_pubmethodSystem_CAPS_staticGetText(TextDataFormat)

Returns a string containing text data on the Clipboard.

System_CAPS_pubmethodSystem_CAPS_staticIsCurrent(IDataObject)

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

System_CAPS_pubmethodSystem_CAPS_staticSetAudio(Byte[])

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

System_CAPS_pubmethodSystem_CAPS_staticSetAudio(Stream)

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

System_CAPS_pubmethodSystem_CAPS_staticSetData(String, Object)

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

System_CAPS_pubmethodSystem_CAPS_staticSetDataObject(Object)

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

System_CAPS_pubmethodSystem_CAPS_staticSetDataObject(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.

System_CAPS_pubmethodSystem_CAPS_staticSetFileDropList(StringCollection)

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

System_CAPS_pubmethodSystem_CAPS_staticSetImage(BitmapSource)

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

System_CAPS_pubmethodSystem_CAPS_staticSetText(String)

Stores UnicodeText data on the Clipboard.

System_CAPS_pubmethodSystem_CAPS_staticSetText(String, TextDataFormat)

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

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.

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

.NET Framework
Available since 3.0
Silverlight
Available since 4.0
Windows Phone Silverlight
Available since 7.1

Any public static (Shared in Visual Basic) members of this type are thread safe. Any instance members are not guaranteed to be thread safe.

Return to top
Show:
© 2016 Microsoft