Skip to content

Latest commit

 

History

History
42 lines (33 loc) · 1.25 KB

README.md

File metadata and controls

42 lines (33 loc) · 1.25 KB

Clippy Build status NuGet version

Treat the clipboard like a TextReader and TextWriter

Installation

PM> Install-Package MasterDevs.Clippy

Usage

We use System.Windows.Clipboard to read and write to the clipboard. Since this is an OLE object it needs to be accessed from a STAThread. If you are in a WPF application, you shouldn't need to worry about this. If you are in a console application, you will need to make sure that you are using a STAThread. The easiest way is to decorate your startup method with the STAThreadAttribute like so:

[STAThread]
private static int Main(string[] args)
{
  // ...
}

Reading from the clipboard

To read from the clipboard, simply create a new ClipboardReader

using (var clippy = new ClipboardReader())
{
  var clipboardText = clippy.ReadToEnd();
}

Writing to the clipboard

To write to the clipboard, simply create a ClipboardWriter

using (var clippy = new ClipboardWriter())
{
  clippy.Write("Hello World");
}