Language: EN

csharp-textcopy

Simplify Clipboard Manipulation in C# with TextCopy

TextCopy is an open-source library for C# that facilitates interaction with the clipboard in .NET applications.

It is a lightweight and efficient tool designed to work seamlessly across different platforms, including Windows, macOS, and Linux.

TextCopy simplifies the tasks of copying and pasting text to and from the clipboard, offering a simple and direct API.

Installing TextCopy

To get started using TextCopy in your .NET project, you first need to install the library via NuGet. You can do this using the NuGet Package Manager in Visual Studio or by using the NuGet console.

Install-Package TextCopy

How to Use TextCopy

Once you have installed TextCopy, you can start using it to copy and paste text in your application. Below are several examples illustrating how to interact with the clipboard using TextCopy.

Copy Text to Clipboard

This example shows how to copy a string of text to the clipboard.

using TextCopy;

class Program
{
    static void Main(string[] args)
    {
        // Text to copy to the clipboard
        string textToCopy = "Hello, world!";
        
        // Copy the text to the clipboard
        ClipboardService.SetText(textToCopy);
        
        Console.WriteLine("Text copied to the clipboard.");
    }
}

Paste Text from Clipboard

In this example, it shows how to paste (retrieve) a string of text from the clipboard.

using TextCopy;

class Program
{
    static void Main(string[] args)
    {
        // Paste (retrieve) the text from the clipboard
        string pastedText = ClipboardService.GetText();
        
        Console.WriteLine($"Text pasted from the clipboard: {pastedText}");
    }
}

TextCopy is Open Source and all its code and documentation are available in the project repository at GitHub - CopyText/TextCopy.