This documentation is archived and is not being maintained.

Placing Data on the Clipboard

Visual Studio .NET 2003

A number of applications use the Clipboard as a temporary repository for data. For example, word processors use it during cut/copy/paste operations. Accessing the Clipboard and storing data there with a Windows application is made possible through the use of the SetDataObject method, which stores the data on the Clipboard using the IDataObject interface. The SetDataObject method does this so that, when the data is later retrieved from the Clipboard, it can be done so in a variety of formats.

To place data on the Clipboard

  • Use the SetDataObject method to send data to the Clipboard.

    The following example shows how to make the Click event of a Button control send the text of a TextBox control to the Clipboard:

    ' Visual Basic
    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
       Clipboard.SetDataObject(TextBox1.Text)
    End Sub
    
    // C#
    private void button1_Click(object sender, System.EventArgs e)
    {
       Clipboard.SetDataObject(textBox1.Text);
    }
    

See Also

Retrieving Information from the Clipboard | Drag-and-Drop Operations and Clipboard Support

Show: