Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
Collapse
Feed
Dashboard
Wallet
Learn
Achievements
Network
Rewards
SharpGPT
Premium
Contribute
Article
Blog
Video
Ebook
Interview Question
Register
Login
How To Copy Data To Clipboard In C#
WhatsApp
Mahesh Chand
5y
427.1k
0
9
100
Article
ClipboardSampleInCSharp.zip
If you use CTRL+C, some data or files are copied to the system clipboard memory and when you use CTRL+V, the data is copied back to wherever you paste it. The Clipboard class provides functionality to place data to and retrieve data from the clipboard.
Storing and Retrieving Data
Clipboard has static methods to copy and paste data. The SetDataObject method is used to store data that is in object format to the clipboard. The following code snippet copies selected text from a RichTextBoc control to the clipboard.
Clipboard.SetDataObject(richTextBox1.SelectedText);
The GetDataObject method reads data back from the clipboard. The following code snippet gets data from the clipboard and displays in a Label control.
// Retrieves data
IDataObject iData = Clipboard.GetDataObject();
// Is Data Text?
if
(iData.GetDataPresent(DataFormats.Text))
label1.Text = (String)iData.GetData(DataFormats.Text);
else
label1.Text =
"Data not found."
;
Clear Clipboard
Clear method removes all data from the Clipboard.
Clipboard.Clear();
Summary
The Clipboard class provides methods to save to and retrieve data from system clipboard.
C# Clipboard copy
Up Next
Ebook Download
View all
Frontend Developer Interview Questions and Answers
Read by 945 people
Download Now!
Learn
View all
Mindcracker
Founded in 2003, Mindcracker is the authority in custom software development and innovation. We put best practices into action. We deliver solutions based on consumer and industry analysis.
Membership not found