SharpClipboard
![sc-donate](https://github.com/willy-kimura/sharpclipboard/raw/HEAD/Assets/Donate-PayPal-blue.svg)
SharpClipboard is a clipboard-monitoring library for .NET that listens to the system's clipboard entries,
allowing developers to tap into the rich capabilities of determining the clipboard's contents at runtime.
Here's a screenshot and below a usage-preview of the library's features:
![sc-usage](https://github.com/willy-kimura/sharpclipboard/raw/HEAD/Assets/sharpclipboard-usage-01.gif)
Installation
To install via the NuGet Package Manager Console, type:
Install-Package SharpClipboard -Version 2.0.7
You can also download the assembly and add it to Visual Studio's Toolbox; plus not forgetting its documentation.
Features
Here's a comprehensive list of the features available:
Usage
If you prefer working with the Designer, simply add the library to Visual Studio's Toolbox and use the
Properties window to change its options:
![sc-preview-02](https://github.com/willy-kimura/sharpclipboard/raw/HEAD/Assets/sharpclipboard-preview-02.png)
To use it in code, first import WK.Libraries.SharpClipboardNS
- the code below will then assist you:
var clipboard = new SharpClipboard();
clipboard.ClipboardChanged += ClipboardChanged;
private void ClipboardChanged(Object sender, ClipboardChangedEventArgs e)
{
if (e.ContentType == SharpClipboard.ContentTypes.Text)
{
Debug.WriteLine(clipboard.ClipboardText);
}
else if (e.ContentType == SharpClipboard.ContentTypes.Image)
{
Image img = clipboard.ClipboardImage;
}
else if (e.ContentType == SharpClipboard.ContentTypes.Files)
{
Debug.WriteLine(clipboard.ClipboardFiles.ToArray());
Debug.WriteLine(clipboard.ClipboardFile);
}
else if (e.ContentType == SharpClipboard.ContentTypes.Other)
{
}
}
You can also get the details of the application from where the clipboard's contents were cut/copied from using the ClipboardChanged
argument property SourceApplication
:
private void ClipboardChanged(Object sender, SharpClipboard.ClipboardChangedEventArgs e)
{
Debug.WriteLine(e.SourceApplication.Name);
Debug.WriteLine(e.SourceApplication.Title);
Debug.WriteLine(e.SourceApplication.ID.ToString());
Debug.WriteLine(e.SourceApplication.Path);
}
This option could come in handy especially when you're building a clipboard-monitoring application where users may feel the need to know where every recorded cut/copy action occurred.
To manually parse the content after a cut/copy has been detected, you can use the argument property e.Content
in the ClipboardChanged
event:
private void ClipboardChanged(Object sender, ClipboardChangedEventArgs e)
{
string text = e.Content.ToString();
Image img = (Image)e.Content;
List<string> files = (List<string>)e.Content;
}
Donate
Hey, you can always buy me a coffee if this component library (or others) has been of value to you.