Clipboard.ContainsText 方法

定義

指出剪貼簿上是否有文字資料。Indicates whether there is text data on the Clipboard.

多載

ContainsText()

指出剪貼簿上是否有 TextUnicodeText 格式的資料,格式依作業系統而定。Indicates whether there is data on the Clipboard in the Text or UnicodeText format, depending on the operating system.

ContainsText(TextDataFormat)

指出剪貼簿上是否有由所指定 TextDataFormat 值代表之格式的文字資料。Indicates whether there is text data on the Clipboard in the format indicated by the specified TextDataFormat value.

ContainsText()

指出剪貼簿上是否有 TextUnicodeText 格式的資料,格式依作業系統而定。Indicates whether there is data on the Clipboard in the Text or UnicodeText format, depending on the operating system.

public:
 static bool ContainsText();
public static bool ContainsText ();
static member ContainsText : unit -> bool
Public Shared Function ContainsText () As Boolean

傳回

Boolean

如果剪貼簿上有文字資料,則為 true,否則為 falsetrue if there is text data on the Clipboard; otherwise, false.

例外狀況

無法清除剪貼簿。The Clipboard could not be cleared. 這通常在剪貼簿由另一個處理序使用時發生。This typically occurs when the Clipboard is being used by another process.

目前執行緒 (Thread) 不是在單一執行緒 Apartment (STA) 模式。The current thread is not in single-threaded apartment (STA) mode. STAThreadAttribute 加入至應用程式的 Main 方法。Add the STAThreadAttribute to your application's Main method.

範例

下列範例示範 ContainsText 類似于此多載之方法的多載。The following example demonstrates an overload of the ContainsText method that is similar to this overload.

// Demonstrates SetText, ContainsText, and GetText.
public String SwapClipboardHtmlText(String replacementHtmlText)
{
    String returnHtmlText = null;
    if (Clipboard.ContainsText(TextDataFormat.Html))
    {
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html);
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html);
    }
    return returnHtmlText;
}
' Demonstrates SetText, ContainsText, and GetText.
Public Function SwapClipboardHtmlText( _
    ByVal replacementHtmlText As String) As String

    Dim returnHtmlText As String = Nothing

    If (Clipboard.ContainsText(TextDataFormat.Html)) Then
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html)
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
    End If

    Return returnHtmlText

End Function

備註

這個方法會以 UnicodeText WINDOWS Xp Home Edition、WINDOWS Xp Professional、Windows Server 2003 和 windows 2000 上的格式來檢查資料是否存在。This method checks for the presence of data in the UnicodeText format on Windows XP Home Edition, Windows XP Professional, Windows Server 2003 and Windows 2000. 否則,此方法會檢查資料的格式是否存在 TextOtherwise, this method checks for the presence of data in the Text format.

使用這個方法來判斷剪貼簿是否包含文字資料,然後再使用方法進行抓取 GetTextUse this method to determine whether the Clipboard contains text data before retrieving it with the GetText method.

注意

Clipboard類別只能用在設定為單一線程單元 (STA) 模式的執行緒中。The Clipboard class can only be used in threads set to single thread apartment (STA) mode. 若要使用這個類別,請確定您的 Main 方法是以 STAThreadAttribute 屬性標記。To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

另請參閱

適用於

ContainsText(TextDataFormat)

指出剪貼簿上是否有由所指定 TextDataFormat 值代表之格式的文字資料。Indicates whether there is text data on the Clipboard in the format indicated by the specified TextDataFormat value.

public:
 static bool ContainsText(System::Windows::Forms::TextDataFormat format);
public static bool ContainsText (System.Windows.Forms.TextDataFormat format);
static member ContainsText : System.Windows.Forms.TextDataFormat -> bool
Public Shared Function ContainsText (format As TextDataFormat) As Boolean

參數

format
TextDataFormat

其中一個 TextDataFormat 值。One of the TextDataFormat values.

傳回

Boolean

如果剪貼簿上有為 format 所指定值的文字資料,則為 true,否則為 falsetrue if there is text data on the Clipboard in the value specified for format; otherwise, false.

例外狀況

無法清除剪貼簿。The Clipboard could not be cleared. 這通常在剪貼簿由另一個處理序使用時發生。This typically occurs when the Clipboard is being used by another process.

目前執行緒 (Thread) 不是在單一執行緒 Apartment (STA) 模式。The current thread is not in single-threaded apartment (STA) mode. STAThreadAttribute 加入至應用程式的 Main 方法。Add the STAThreadAttribute to your application's Main method.

format 不是有效的 TextDataFormat 值。format is not a valid TextDataFormat value.

範例

下列範例示範這個成員。The following example demonstrates this member.

// Demonstrates SetText, ContainsText, and GetText.
public String SwapClipboardHtmlText(String replacementHtmlText)
{
    String returnHtmlText = null;
    if (Clipboard.ContainsText(TextDataFormat.Html))
    {
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html);
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html);
    }
    return returnHtmlText;
}
' Demonstrates SetText, ContainsText, and GetText.
Public Function SwapClipboardHtmlText( _
    ByVal replacementHtmlText As String) As String

    Dim returnHtmlText As String = Nothing

    If (Clipboard.ContainsText(TextDataFormat.Html)) Then
        returnHtmlText = Clipboard.GetText(TextDataFormat.Html)
        Clipboard.SetText(replacementHtmlText, TextDataFormat.Html)
    End If

    Return returnHtmlText

End Function

備註

使用這個方法來判斷剪貼簿是否包含文字資料,然後再使用方法進行抓取 GetTextUse this method to determine whether the Clipboard contains text data before retrieving it with the GetText method.

注意

Clipboard類別只能用在設定為單一線程單元 (STA) 模式的執行緒中。The Clipboard class can only be used in threads set to single thread apartment (STA) mode. 若要使用這個類別,請確定您的 Main 方法是以 STAThreadAttribute 屬性標記。To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

另請參閱

適用於