Share via


Clipboard.GetData(String) 方法

定义

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

public:
 static System::Object ^ GetData(System::String ^ format);
public static object GetData (string format);
static member GetData : string -> obj
Public Shared Function GetData (format As String) As Object

参数

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

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

' If there is HTML data on the clipboard, retrieve it.
Dim htmlData As String
If IsHTMLDataOnClipboard Then

    htmlData = Clipboard.GetText(TextDataFormat.Html)

End If

适用于

另请参阅