Clipboard.SetData Method (System.Windows)

Switch View :
ScriptFree
.NET Framework Class Library
Clipboard.SetData Method

Stores the specified data on the Clipboard in the specified format.

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

Visual Basic
Public Shared Sub SetData ( _
	format As String, _
	data As Object _
)
C#
public static void SetData(
	string format,
	Object data
)
Visual C++
public:
static void SetData(
	String^ format, 
	Object^ data
)
F#
static member SetData : 
        format:string * 
        data:Object -> unit 

Parameters

format
Type: System.String
A string that specifies the format to use to store the data. See the DataFormats class for a set of predefined data formats.
data
Type: System.Object
An object representing the data to store on the Clipboard.
Remarks

This method adds data with auto-conversion enabled if the corresponding data format is FileDrop or Bitmap. Otherwise, auto-conversion is disabled.

Examples

The following example demonstrates the use of this method.

Visual Basic

' 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."

' After this call, the data (string) is placed on the clipboard and tagged
' with a data format of "Text".
Clipboard.SetData(DataFormats.Text, CType(textData, Object))


C#


// 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.";

// After this call, the data (string) is placed on the clipboard and tagged
// with a data format of "Text".
Clipboard.SetData(DataFormats.Text, (Object)textData);


Version Information

.NET Framework

Supported in: 4, 3.5, 3.0

.NET Framework Client Profile

Supported in: 4, 3.5 SP1
Platforms

Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

The .NET Framework does not support all versions of every platform. For a list of the supported versions, see .NET Framework System Requirements.
See Also

Reference

Community Content

soyuz
Data type must be marked with [Serializable] attribute
Data put into clipboard must be marked as Serializable.