Clipboard.GetData(String) 方法

定義

從剪貼簿擷取指定之格式的資料。Retrieves data in a specified format from the Clipboard.

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

字串,會指定要擷取的資料格式。A string that specifies the format of the data to retrieve. 如需一組預先定義的資料格式,請參閱 DataFormats 類別。For a set of predefined data formats, see the DataFormats class.

傳回

物件,包含指定之格式的資料,如果資料無法使用指定的格式,則傳回 nullAn object that contains the data in the specified format, or null if the data is unavailable in the specified format.

例外狀況

formatnullformat is null.

範例

下列範例示範如何使用這個方法。The following example demonstrates the use of this method.


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

適用於

另請參閱