Clipboard.GetData(String) 方法

定义

从剪贴板检索指定格式的数据。

public static object GetData (string format);

参数

format
String

一个字符串,指定要检索的数据的格式。 有关预定义数据格式集,请参阅 DataFormats 类。

返回

包含指定格式数据的对象;如果没有指定格式的数据,则为 null

例外

formatnull

示例

以下示例演示了此方法的使用。


// After this line executes, IsHTMLDataOnClipboard will be true if
// HTML data is available natively on the clipboard; if not, it 
// will be false.
bool IsHTMLDataOnClipboard = Clipboard.ContainsData(DataFormats.Html);

// If there is HTML data on the clipboard, retrieve it.
string htmlData;
if(IsHTMLDataOnClipboard)
{

    htmlData = Clipboard.GetText(TextDataFormat.Html);
}

适用于

产品 版本
.NET Framework 3.0, 3.5, 4.0, 4.5, 4.5.1, 4.5.2, 4.6, 4.6.1, 4.6.2, 4.7, 4.7.1, 4.7.2, 4.8, 4.8.1
Windows Desktop 3.0, 3.1, 5, 6, 7, 8, 9

另请参阅