How to copy data to clipboard in C#
There are many ways to copy to clipboard in C#:1) Using Clipbpard.SetText() Method from using using System.Windows.Forms; namespace.
2) Using Threading.
Example using Clipbpard.SetText()
using System;
using System.Windows;
public class Program
{
public static void Main()
{
Clipboard.SetText("Hello, clipboard");
Console.WriteLine(input);
}
}
Example using Threading
using System;
using System.Threading.ThreadStateException;
public class Program
{
public static void Main()
{
Thread thread = new Thread(() => Clipboard.SetText("String to be copied to clipboard"));
thread.SetApartmentState(ApartmentState.STA); //Set the thread to STA
thread.Start();
thread.Join();
}
}