Clipboard.SetDataObject メソッド
定義
重要
一部の情報は、リリース前に大きく変更される可能性があるプレリリースされた製品に関するものです。 Microsoft は、ここに記載されている情報について、明示または黙示を問わず、一切保証しません。
指定したデータ オブジェクトをシステム クリップボードに格納します。
オーバーロード
| 名前 | 説明 |
|---|---|
| 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 呼び出しによってクリップボードに以前に配置されたデータ オブジェクトを決定します。