C # send data to the clipboard and obtain data from the clipboard

Source: Internet
Author: User

Take winform as an example. design two textbox controls named textbox1 and textbox2 respectively. design two button controls named btn_send and btn_get respectively.

The Code is as follows:

<Span style = "font-family: Microsoft yahei; font-size: 14px;"> private void btn_send_click (Object sender, eventargs e) {try {clipboard. settext (textbox1.text); MessageBox. show ("the text box content has been successfully copied to the clipboard! ");} Catch (exception) {MessageBox. Show (" error! ") ;}} Private void btn_get_click (Object sender, eventargs e) {string txt2 = textbox2.text; try {idataobject idata = clipboard. getdataobject (); If (idata. getdatapresent (dataformats. text) {// MessageBox. show (string) idata. getdata (dataformats. text); textbox2.text = (string) idata. getdata (dataformats. unicodetext);} else {MessageBox. show ("data in the current clipboard cannot be converted to text", "error") ;}} catch (exception) {MessageBox. show ("error") ;}}</span>


Source code download

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.