Introduction
How many times have you wanted a library that manages all objects entering and leaving the windows clipboard? Maybe without having to handle the various types of objects ..
Here it is!
Nothing could be simpler. This library will handle everything for you through a series of delegates to communicate the appearance of new notes and a thread
that has the task of effectively monitor system clipboard.
This library track:
- Text and html;
- Images;
- Files;
The library needs, for now, a Windows Forms object for the proper management of the delegates.
Future versions will replace this part with an interface that will manage the delegates.
It will be for those who will implement this interface to manage the Invoke in the form (or XAML view) correctly.
Using the code
string[] files = ClipboardManager.GetClipboardFiles();
Image image = ClipboardManager.GetClipboardImage();
string text = ClipboardManager.GetClipboardText();
ClipboardManager.SetClipboardFiles(new string[] { "file1", "file2" });
ClipboardManager.SetClipboardImage(new Bitmap("path"));
You can use the library only in a static way. This way you can read and write files, images and text to the clipboard.
Please note that in case the clipboard was empty or tried, for example, to read a text in the clipboard when there is a file, static methods will return always null.
The use of "Clipboard Manager" as static class is not recommended in cases where there is no certainty of what's in the clipboard.
ClipboardManager manager = new ClipboardManager(this);
manager.Type = ClipboardManager.CheckType.All;
manager.OnNewFilesFound += (sender, eventArg) =>
{
foreach (String item in eventArg)
{
Console.WriteLine("New file found in clipboard : {0}", item);
}
};
manager.OnNewImageFound += (sender, eventArg) =>
{
Console.WriteLine("New image found in clipboard -> Width: {0} , Height: {1}",
eventArg.Width, eventArg.Height);
};
manager.OnNewTextFound += (sender, eventArg) =>
{
Console.WriteLine("New text found in clipboard : {0}", eventArg);
};
manager.StartChecking();
manager.Dispose();
Using the class "Clipboard Manager" as an instance you have the possibility of having, by event, reporting that a new object is entered into the clipboard.
This class is very convenient because it allows the user to manage the objects in the clipboard in near real time (the manager operates through a thread and so there
may be about a one second delay).
History
02/10/2012: Version 1.0.0.1 (Resolved image comparison bug + adding test project)
28/09/2012: Version 1.0.0.0
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.