Copy and paste text to and from the clipboard C#

Using the clipboard to copy and paste text is simple. Use the Clipboard object's SetText method to copy text to the clipboard.

// 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.
// Paste text from the clipboard.
private void btnPaste_Click(object sender, EventArgs e)
{
txtPaste.Text = Clipboard.GetText();
}

   

 

What did you think of this article?




Trackbacks
  • No trackbacks exist for this post.
Comments
  • No comments exist for this post.
Leave a comment

Submitted comments are subject to moderation before being displayed.

 Name

 Email (will not be published)

 Website

Your comment is 0 characters limited to 3000 characters.