C#richtextbox implementation (copy, cut, paste, select All)

Source: Internet
Author: User

Ext: http://www.cnblogs.com/JuneZhang/archive/2011/05/20/2051973.html

There are two main ways to implement this menu:

First: implemented by sending keystrokes to the application.

First focus to the currently active RichTextBox, and then by sending the keystroke command to implement the Operation function

Richtextbox1.focus ();
Sendkeys.send ("^a")/Select All
Sendkeys.send ("^c");/copy
Sendkeys.send ("^x");//Cut
Sendkeys.send ("^v");//paste

The second type: directly manipulate the Clipboard implementation by command

Copy
Clipboard.setdata (DATAFORMATS.RTF, RICHTEXTBOX1.SELECTEDRTF)//Copy RTF data to clipboard
Shear
Clipboard.setdata (DATAFORMATS.RTF, RICHTEXTBOX1.SELECTEDRTF)//Copy RTF data to clipboard
Richtextbox1.selectedrtf= "" "" ", or the current selection of RTF content to clear out, the current implementation of the cut function.
Paste
Richtextbox1.paste ()//paste the data on the Clipboard to the target RichTextBox
Select All (there are two ways to select all of them)
Richtextbox1.focus ()//sets the first focus to the current active RichTextBox, which is important, otherwise it will not execute correctly
The other is through the select (int start,int length) method to implement
Richtextbox1.select (0, RichTextBox1.Rtf.Length);//richtextbox1.rtf.length represents the length of text in RichTextBox
One is to directly adopt the SelectAll () method provided in the NET Framework to select all
Richtextbox1.selectall ();
Related Article

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.