Clipboard 类

定义

提供便于将数据传入和传出系统剪贴板的静态方法。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
继承
Clipboard

示例

下面的示例演示如何将数据添加到系统剪贴板。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))

注解

适用于 Windows 的所有应用程序共享系统剪贴板,因此当你切换到另一个应用程序时,内容可能会更改。All applications for Windows share the system Clipboard, so the contents are subject to change when you switch to another application.

有关可用于类的预定义格式的列表 Clipboard ,请参见 DataFormats 类。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.

  • 粘贴操作需要用户启动 (Ctrl + V、粘贴菜单) 。Paste operations need to be user initiated (Ctrl-V, Paste Menu).

  • 副本只能对用户选择的内容。Copy can only be on user selected content.

  • 在复制或剪切时,部分信任代码将纯文本和 Extensible Application Markup Language (XAML) 放到剪贴板上。On copy or cut, partial trust code puts plaintext and Extensible Application Markup Language (XAML) on to the clipboard. 纯文本包含文本、Unicode 文本、OEM (对象交换模型) 文本和 CSV (逗号分隔值) 。Plaintext includes text, Unicode text, OEM (Object Exchange Model) text, and CSV (Comma-separated values).

  • 在粘贴时,如果该内容的源来自相同的受信任或受信任的站点,则 Windows Presentation Foundation (WPF) 会将 Extensible Application Markup Language (XAML。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:

    • 部分信任应用程序可以从完全信任的应用程序 Extensible Application Markup Language (XAML) 粘贴。A partial trust application can paste Extensible Application Markup Language (XAML) from a full trust application.

    • 部分信任应用程序可以从部分信任的应用程序 Extensible Application Markup Language (XAML) 粘贴。A partial trust application can paste Extensible Application Markup Language (XAML) from a partial trust application.

    • 完全信任应用程序只能从另一个完全受信任的应用程序中粘贴 XAML。A full trust application can paste XAML only from another fully trusted application.

    • 非 Windows Presentation Foundation (WPF) 完全信任应用程序可以检查剪贴板上的 ApplicationTrust 格式,并根据需要净化 XAML。A non-Windows Presentation Foundation (WPF) full trust application can examine the ApplicationTrust format on the clipboard and sanitize the XAML if appropriate.

方法

Clear()

从系统剪贴板中清除任何数据。Clears any data from the system Clipboard.

ContainsAudio()

查询剪贴板上是否存在 WaveAudio 数据格式的数据。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()

查询剪贴板上是否存在 FileDrop 数据格式的数据。Queries the Clipboard for the presence of data in the FileDrop data format.

ContainsImage()

查询剪贴板上是否存在 Bitmap 数据格式的数据。Queries the Clipboard for the presence of data in the Bitmap data format.

ContainsText()

查询剪贴板上是否存在 UnicodeText 格式的数据。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()

永久地添加 Clipboard 上的数据,使其在数据的原始应用程序关闭后可用。Permanently adds the data that is on the Clipboard so that it is available after the data's original application closes.

GetAudioStream()

返回 WaveAudio 数据格式的剪贴板数据流。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()

从剪贴板返回一个 BitmapSource 对象,其中包含 Bitmap 格式的数据。Returns a BitmapSource object from the Clipboard that contains data in the Bitmap format.

GetText()

返回一个包含剪贴板上 UnicodeText 数据的字符串。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[])

将音频数据(WaveAudio 数据格式)存储在剪贴板上。Stores audio data (WaveAudio data format) on the Clipboard. 音频数据指定为字节数组。The audio data is specified as a byte array.

SetAudio(Stream)

将音频数据(WaveAudio 数据格式)存储在剪贴板上。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)

将指定的非永久性数据对象放置在系统剪贴板上。Places a specified non-persistent data object on the system Clipboard.

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)

FileDrop 数据存储在剪贴板上。Stores FileDrop data on the Clipboard. 拖放文件列表指定为字符串集合。The dropped file list is specified as a string collection.

SetImage(BitmapSource)

Bitmap 数据存储在剪贴板上。Stores Bitmap data on the Clipboard. 图像数据指定为 BitmapSourceThe image data is specified as a BitmapSource.

SetText(String)

UnicodeText 数据存储在剪贴板上。Stores UnicodeText data on the Clipboard.

SetText(String, TextDataFormat)

以指定的文本数据格式在剪贴板上存储文本数据。Stores text data on the Clipboard in a specified text data format. 将要存储的 UnicodeText 数据指定为一个字符串。The UnicodeText data to store is specified as a string.

适用于

另请参阅