語言

Clipboard.IsCurrent(IDataObject) 方法

定義

將指定的資料物件與剪貼簿的內容進行比較。

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

一個用來與系統剪貼簿內容比較的資料物件。

傳回

true如果指定的資料物件與系統剪貼簿上的相同;否則,。 false

例外狀況

data 是 null。

存取剪貼簿時發生錯誤。 例外細節將包含識別特定錯誤的 ; HResult 參見 ErrorCode。

範例

以下範例展示了此方法的使用。


               // 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)

備註

使用此方法判斷先前放在剪貼簿上的資料物件是否仍然存在且未被修改。

適用於