The Clipboard is one of the most common features of the Windows operating system, which is used to pass data from one application to another, such as text, images, or even program objects. However, the Clipboard also has a limit, it can only point to a piece of content at a certain time, each subsequent copy of the content will replace the previous content. To manipulate the Clipboard (including read and write content) in C #, you need to use the System.Windows.Forms.Clipboard class.
Clipboard class:
Provides methods for placing data on the system Clipboard and retrieving data from it, and this class cannot be inherited.
Namespaces: System.Windows.Forms
Assembly: System.Windows.Forms (in System.Windows.Forms.dll)
Syntax: public sealed class Clipboard
Clipboard::getdataobject Method:
Grammar:
public:staticGetDataObject()
return value
Type: System.windows.forms::idataobject
A idataobject that represents the current data in the system Clipboard, or a null reference if there is no data in the Clipboard (Nothing in Visual Basic).
Because the data type of the object returned from the Clipboard can be different, this method returns the data in IDataObject. You can then use the IDataObject interface method to extract data with the correct data type.
Clipboard::containsimage Method:
Indicates whether there is a Bitmap format or data that can be converted to this format in the Clipboard
Use this method to determine whether the Clipboard contains image data before retrieving the image data using the GetImage method.
Grammar:
public:staticboolContainsImage()
return value
Type: System::boolean
True if image data is present in the Clipboard; otherwise, false.
Clipboard::getimage Method:
Indicates whether the Clipboard exists
Before you use this method to retrieve image data, use the ContainsImage method to determine whether the Clipboard contains image data.
Grammar:
public:staticGetImage()
return value
Type: System.drawing::image
An image that represents the Clipboard image data, or a null reference if the Clipboard does not contain any bitmap format or data that can be converted to that format.
public System.Drawing.Image SwapClipboardImage( System.Drawing.Image replacementImage){ System.Drawing.Image returnImage = null; if (Clipboard.ContainsImage()) { returnImage = Clipboard.GetImage(); Clipboard.SetImage(replacementImage); } return returnImage;}
Copyright NOTICE: This article for Bo Master original article, without Bo Master permission not reproduced.
C # analog PRTSCN for screenshot prep-clipboard operations