語言

Clipboard.ContainsData(String) 方法

定義

查詢剪貼簿是否有指定資料格式的資料。

public:
 static bool ContainsData(System::String ^ format);
public static bool ContainsData(string format);
static member ContainsData : string -> bool
Public Shared Function ContainsData (format As String) As Boolean

參數

format
String

要注意的資料格式。 請參閱 DataFormats 預設格式。

傳回

true如果剪貼簿上有指定格式的資料;否則,。 false

例外狀況

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

備註

查詢資料格式BitmapFileDrop或資料是否true能自動轉換成指定的資料格式。 對於其他資料格式,只有當指定格式在剪貼簿上原生可用時,此方法才會回傳 true 。

適用於

另請參閱