Copy and paste text to and from the clipboard C#

copy and paste clipboard text

Using the clipboard to copy and paste text is simple. Use the Clipboard object’s SetText method to copy text to the clipboard as in the following code.

// Copy text to the clipboard.
private void btnCopy_Click(object sender, EventArgs e)
{
    Clipboard.SetText(txtCopy.Text);
}

Use the Clipboard object’s GetText method to retrieve the text that’s in the clipboard as in the following code.

// Paste text from the clipboard.
private void btnPaste_Click(object sender, EventArgs e)
{
    txtPaste.Text = Clipboard.GetText();
}

That’s all there is to it! In later posts I’ll show how you can copy and paste other kinds of data such as images or objects of your own creation.


Download Example   Follow me on Twitter   RSS feed




This entry was posted in clipboard and tagged , , , , , , , , , , , . Bookmark the permalink.

Leave a Reply

Your email address will not be published. Required fields are marked *