.NET Framework Class Library
Clipboard..::.SetDataObject Method (Object, Boolean, Int32, Int32)

Attempts to place data on the system Clipboard the specified number of times and with the specified delay between attempts, optionally leaving the data on the Clipboard after the application exits.

Namespace:  System.Windows.Forms
Assembly:  System.Windows.Forms (in System.Windows.Forms.dll)
Syntax

Visual Basic (Declaration)
<UIPermissionAttribute(SecurityAction.Demand, Clipboard := UIPermissionClipboard.OwnClipboard)> _
Public Shared Sub SetDataObject ( _
    data As Object, _
    copy As Boolean, _
    retryTimes As Integer, _
    retryDelay As Integer _
)
Visual Basic (Usage)
Dim data As Object
Dim copy As Boolean
Dim retryTimes As Integer
Dim retryDelay As Integer

Clipboard.SetDataObject(data, copy, retryTimes, _
    retryDelay)
C#
[UIPermissionAttribute(SecurityAction.Demand, Clipboard = UIPermissionClipboard.OwnClipboard)]
public static void SetDataObject(
    Object data,
    bool copy,
    int retryTimes,
    int retryDelay
)
Visual C++
[UIPermissionAttribute(SecurityAction::Demand, Clipboard = UIPermissionClipboard::OwnClipboard)]
public:
static void SetDataObject(
    Object^ data, 
    bool copy, 
    int retryTimes, 
    int retryDelay
)
JScript
public static function SetDataObject(
    data : Object, 
    copy : boolean, 
    retryTimes : int, 
    retryDelay : int
)

Parameters

data
Type: System..::.Object
The data to place on the Clipboard.
copy
Type: System..::.Boolean
true if you want data to remain on the Clipboard after this application exits; otherwise, false.
retryTimes
Type: System..::.Int32
The number of times to attempt placing the data on the Clipboard.
retryDelay
Type: System..::.Int32
The number of milliseconds to pause between attempts.
Exceptions

ExceptionCondition
ThreadStateException

The current thread is not in single-threaded apartment (STA) mode. Add the STAThreadAttribute to your application's Main method.

ArgumentNullException

data is nullNothingnullptra null reference (Nothing in Visual Basic).

ArgumentOutOfRangeException

retryTimes is less than zero.

-or-

retryDelay is less than zero.

ExternalException

Data could not be placed on the Clipboard. This typically occurs when the Clipboard is being used by another process.

Remarks

Adding data to the Clipboard can occasionally fail if the Clipboard is busy with another thread or application. This method is useful to work around this issue in environments with heavy Clipboard use.

If the copy parameter is false, the data will be deleted from system Clipboard when the application exits.

NoteNote:

An object must be serializable for it to be put on the Clipboard. If you pass a non-serializable object to this method, it will fail without throwing an exception. See Serialization for more information on serialization.

The Clipboard class can only be used in threads set to single thread apartment (STA) mode. To use this class, ensure that your Main method is marked with the STAThreadAttribute attribute.

.NET Framework Security

Platforms

Windows 7, Windows Vista, Windows XP SP2, Windows XP Media Center Edition, Windows XP Professional x64 Edition, Windows XP Starter Edition, Windows Server 2008 R2, Windows Server 2008, Windows Server 2003, Windows Server 2000 SP4, Windows Millennium Edition, Windows 98

The .NET Framework and .NET Compact Framework do not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
Version Information

.NET Framework

Supported in: 3.5, 3.0, 2.0
See Also

Reference

Tags :


Page view tracker