Clipboard.IsCurrent(IDataObject) 方法

定義

比較指定的資料物件與剪貼簿的內容。Compares a specified data object to the contents of the Clipboard.

public:
 static bool IsCurrent(System::Windows::IDataObject ^ data);
public static bool IsCurrent (System.Windows.IDataObject data);
static member IsCurrent : System.Windows.IDataObject -> bool
Public Shared Function IsCurrent (data As IDataObject) As Boolean

參數

data
IDataObject

要與系統剪貼簿的內容比較的資料物件。A data object to compare to the contents of the system Clipboard.

傳回

如果指定的資料物件符合系統剪貼簿上的內容,則為 true,否則為 falsetrue if the specified data object matches what is on the system Clipboard; otherwise, false.

例外狀況

datanulldata is null.

存取剪貼簿時發生錯誤。An error occurred when accessing the Clipboard. 例外狀況詳細資料將包括識別特定錯誤的 HResult,請參閱 ErrorCodeThe exception details will include an HResult that identifies the specific error; see ErrorCode.

範例

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


               // For this example, the data to be placed on the clipboard is a simple
               // string.
               string textData = "I want to put this string on the clipboard.";
               // The example will enable auto-conversion of data for this data object.
               bool autoConvert = true;

               // Create a new data object, specifying the data format, data to encapsulate, and enabling
               // auto-conversion services.
               DataObject data = new DataObject(DataFormats.UnicodeText, (Object)textData, autoConvert);
               
               // If the data to be copied is supposed to be persisted after the application ends, 
               // then set the second parameter of SetDataObject to true.
               if(persistentData)
               {
                   // Place the persisted data on the clipboard.
                   Clipboard.SetDataObject(data, true);
               }
               else
               {
                   // Place the non-persisted data on the clipboard.
                   Clipboard.SetDataObject(data, false);
               }

               // If you keep a copy of the source data object, you can use the IsCurrent method to see if
               // the data object is still on the clipboard.
               bool isOriginalDataObject = Clipboard.IsCurrent(data);

' For this example, the data to be placed on the clipboard is a simple
' string.
Dim textData As String = "I want to put this string on the clipboard."
' The example will enable auto-conversion of data for this data object.
Dim autoConvert As Boolean = True

' Create a new data object, specifying the data format, data to encapsulate, and enabling
' auto-conversion services.
Dim data As New DataObject(DataFormats.UnicodeText, CType(textData, Object), autoConvert)

' If the data to be copied is supposed to be persisted after the application ends, 
' then set the second parameter of SetDataObject to true.
If persistentData Then
    ' Place the persisted data on the clipboard.
    Clipboard.SetDataObject(data, True)
Else
    ' Place the non-persisted data on the clipboard.
    Clipboard.SetDataObject(data, False)
End If

' If you keep a copy of the source data object, you can use the IsCurrent method to see if
' the data object is still on the clipboard.
Dim isOriginalDataObject As Boolean = Clipboard.IsCurrent(data)

備註

使用這個方法來判斷先前放在剪貼簿上的資料物件是否仍然存在且未修改。Use this method to determine if a data object that was previously placed on the Clipboard is still present and unmodified.

適用於