case
1Mar/101

Use clipboard (copy/paste) in C# console application

net logo.jpg 150x150 Use clipboard (copy/paste) in C# console applicationThis 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");
    }
}

Related posts:

  1. Communicate betwen C# and an embeded Flash application
  2. How to clone (duplicate) an object in ActionScript 3
  3. How to identify at runtime if the swf is in debug or release mode/build
Comments (1) Trackbacks (0)
  1. Thanks!


Leave a comment


*

CommentLuv badge

No trackbacks yet.