Share via


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

例外狀況

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

備註

資料格式 Bitmap 的查詢,如果 FileDrop 資料可以自動轉換成指定的資料格式,則傳回 true 。 針對其他資料格式,只有在剪貼簿上原生提供指定的格式時,這個方法才會傳回 true

適用於

另請參閱