Clipboard.SetDataObject 方法
定義
重要
部分資訊涉及發行前產品,在發行之前可能會有大幅修改。 Microsoft 對此處提供的資訊,不做任何明確或隱含的瑕疵擔保。
將指定的資料物件儲存在系統剪貼簿上。
多載
| 名稱 | Description |
|---|---|
| SetDataObject(Object) |
將指定的非持久性資料物件放入系統剪貼簿。 |
| SetDataObject(Object, Boolean) |
將指定的資料物件置於系統剪貼簿,並接受一個布林參數,指示該應用程式退出時是否應保留該資料物件。 |
SetDataObject(Object)
將指定的非持久性資料物件放入系統剪貼簿。
public:
static void SetDataObject(System::Object ^ data);
[System.Security.SecurityCritical]
public static void SetDataObject(object data);
public static void SetDataObject(object data);
[<System.Security.SecurityCritical>]
static member SetDataObject : obj -> unit
static member SetDataObject : obj -> unit
Public Shared Sub SetDataObject (data As Object)
參數
- data
- Object
一個資料物件(實作 IDataObject的物件)放在系統的剪貼簿上。
- 屬性
例外狀況
data 是 null。
存取剪貼簿時發生錯誤。 例外細節將包含識別特定錯誤的 ; HResult 參見 ErrorCode。
備註
預設情況下,系統剪貼簿 SetDataObject 上的資料會在應用程式結束時自動從剪貼簿中清除。
Note
在應用程式結束時清除剪貼簿的預設行為可能與其他實作不同,後者可能會在應用程式結束時將資料留在剪貼簿上,而非預設清除。 使用過載並 SetDataObject 指定 copy 參數,就像 true 你不希望應用程式結束時從剪貼簿清除資料一樣。
DataObject 提供介面的基本實作 IDataObject 。
另請參閱
適用於
SetDataObject(Object, Boolean)
將指定的資料物件置於系統剪貼簿,並接受一個布林參數,指示該應用程式退出時是否應保留該資料物件。
public:
static void SetDataObject(System::Object ^ data, bool copy);
[System.Security.SecurityCritical]
public static void SetDataObject(object data, bool copy);
public static void SetDataObject(object data, bool copy);
[<System.Security.SecurityCritical>]
static member SetDataObject : obj * bool -> unit
static member SetDataObject : obj * bool -> unit
Public Shared Sub SetDataObject (data As Object, copy As Boolean)
參數
- data
- Object
一個資料物件(實作 IDataObject的物件)放在系統的剪貼簿上。
- copy
- Boolean
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)
備註
DataObject 提供介面的基本實作 IDataObject 。 IsCurrent 決定最後一次通話時已放置在夾板 SetDataObject 上的資料物件。