语言

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

注解

对数据格式 Bitmap 的查询,或者 FileDrop 如果数据可以自动转换为指定的数据格式,则返回 true 该查询。 对于其他数据格式,此方法仅当指定格式在剪贴板上本机可用时才返回 true 。

适用于

另请参阅