1Mar/100
Use clipboard (copy/paste) in C# console application
This took me few minutes to figure out and was quite annoying. First you must add a reference to System.Windows.Forms in your application. Go to Project -> Add reference, select System.Windows.Forms from .NET tab in the window that just opened. You must avoid the ThreadStateException by applying the STAThread attribute to your Main() function. Then you can use the Clipboard functions without any problems.
1 2 3 4 5 6 7 8 9 | using System; using System.Windows.Forms; class Program { [STAThread] static void Main(string[] args) { Clipboard.SetText("this is in clipboard now"); } } |
May 10th, 2011 - 00:09
Thanks!
June 14th, 2012 - 19:28
Great, thank you. The [STAThread] was what I was missing.
January 10th, 2013 - 12:24
How cone in mvs, you have to add a reference and not just type it in?
February 28th, 2013 - 10:11
Nice!!!