C Method of Sending Data to Clipboard and Fetching Data from Clipboard

  • 2021-07-18 08:47:34
  • OfStack

This article illustrates the method of C # sending data to the clipboard and taking data from the clipboard. Share it for your reference. The details are as follows:

1. Send data to the clipboard


using System.Windows.Forms;
Clipboard.SetText("test");

2. Get data from the clipboard


using System.Windows.Forms;
IDataObject iData = Clipboard.GetDataObject();
if (iData.GetDataPresent(DataFormats.Text))
{
  MessageBox.Show((string)iData.GetData(DataFormats.Text));
}
else
  MessageBox.Show(" Data in the clipboard cannot be converted to text at present "," Errors ");

I hope this article is helpful to everyone's C # programming.


Related articles: