Store and Retrieve Clipboard Content From Windows Clipboard

Introduction

The Computer Clipboard in the computer allows one to place content to and retrieve content from the clipboard. Here in this blog, we will see how to store and retrieve Winodows Clipboard content in C#.

Getting Started

The Clipboard in the computer is a buffer that some operating systems provide for short-term storage and transfer within and between application programs. The clipboard is usually temporary and unnamed, and windows stores the clipboard contents in the computer's RAM.

When we press the CTRL+C some data or files are copied to the Windows clipboard memory and when you use CTRL+V, the data is copied back to wherever you paste it.

Store and Retrieve Content

The Clipboard class provides functionality to place and extract data from it. It has static methods to copy and paste data. The SetDataObject method is used to store one copied text to clipboard at a time in object format. You can store anything but here the following code snippets copy text to clipboard. Note that contents store in the clipboard as an object, datacasting is required to retrieve clipboard contents.

 Clipboard.SetDataObject("Clipboard Text");  

Copy To Clipboard

To extract data back from the clipboard, the clipboard uses another static method that is GetDataObject. The following code snippet gets the data value and displays it in WPF Textblock.

 IDataObject iData = Clipboard.GetDataObject();   
 textBlock1.Text = (String)iData.GetData(DataFormats.Text);   

For clearing clipboard contents stored in it, you can use the clipboard viewer on wondows or below method.

 Clipboard.Clear();   

How many things can be stored in the clipboard?

The clipboard can store one thing at a time. For example, selecting and copying a paragraph of text or an image, is considered one thing. If one thing is currently stored in the clipboard and you copy another thing, it overwrites what's stored in the clipboard.

How much data can the clipboard store?

The amount of data the clipboard can store depends on how much physical memory (RAM) and configured virtual memory (paging file) is in the computer. The more memory a computer has, the more data you can copy to the clipboard.

Only copied data value and images are stored in the clipboard. If you copy a file, only information about the file is stored, not the file itself. For this reason, it's uncommon that you need to increase the amount of data the clipboard can store. However, if you are working with large or raw images, you might encounter a case where more memory is needed to allow the clipboard to store the image data.

View Clipboard Data Value

Windows has a clipboard viewer that displays clipboard contents stored in it. To view the contents, you need to enable clipboard history. To enable the clipboard history follow the below steps, if you already enaled then for opening clipboard content press "Windows" + "V" Key.

Enable Clipboard History on Winodws 10

  1. Open the windows setting by pressing "Windows" + "V" Key.
  2. Then click on System
  3. On the left side panel search for Clipboard and click on it.
  4. Enable hostory, click the on/ off toggle button of clipboard history.

Enable Clipboard History on Winodws 11

  1. Open the windows setting by pressing "Windows" + "V" Key.
  2. Find the "System" menu from the left side panel
  3. On the main panel search for Clipboard and click on it.
  4. Enable hostory, click the on/ off toggle button of clipboard history.

Thanks

Kailash Chandra Behera

An IT Professional with 12 years experience in development life cycle in windows, service and Web based application using Microsoft.Net technologies. Proven record of developing all phases of projects in Microsoft.Net technology from initiation to closure aligning with the company's Business objectives to drive process improvements, competitive advantage and bottom-line gains. -> Good exposure of independently working and developing multiple projects ->Committed to efficient and effective development of projects in a fast-paced and deadline driver environment. Skill :- Develop and design projects in various technologies of Microsoft Technology. Total IT Experience- 13+

Previous Post Next Post

نموذج الاتصال