語言

Clipboard.GetData(String) 方法

定義

從剪貼簿中以指定格式檢索資料。

public:
 static System::Object ^ GetData(System::String ^ format);
public static object GetData(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 當資料無法以指定格式取得時。

例外狀況

format 是 null。

範例

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


// 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

適用於

另請參閱