ShareThis

Monday, January 2, 2012

C# copy to clipboard : how to Copy-Paste to and from clipboard using c#


To make the operations such as copy paste using c#,we have to use the Clipboard Class which provides methods to place data on and retrieve data from the system Clipboard.
Example :-
Copy the text from txtCopy to clipboard
 System.Windows.Forms.Clipboard.SetDataObject(txtCopy.Text, true);
Paste the text from clipboard to txtPaste
IDataObject clipData = Clipboard.GetDataObject();
if (clipData.GetDataPresent(DataFormats.Text))
{
txtPaste.Text = clipData.GetData(DataFormats.Text).ToString();
}
else
{
txtPaste.Text = "Could not retrieve data from the clipboard.";
}

0 comments:

Post a Comment