Add shortcut menu for RichTextBox (copy, cut, paste, select all)

Source: Internet
Author: User

There are two ways to implement the menu function:

First:Send a key to the applicationProgram.

First, focus on the current active RichTextBox, and then send a shortcut 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

 Method 2: using commands to operate the clipboard

 // copy the clipboard. setdata (dataformats. RTF, richtextbox1.selectedrtf); // copy the RTF data to the clipboard // cut the clipboard. setdata (dataformats. RTF, richtextbox1.selectedrtf); // copy the RTF data to the clipboard richtextbox1.selectedrtf = ""; // then clear the currently selected RTF content. The cut function is now enabled. // paste richtextbox1.paste (); // paste the data on the clipboard to the target RichTextBox // select all (both methods are available) richtextbox1.focus (); // set the focus to locate the RichTextBox of the current activity first. This sentence is very important, otherwise it cannot be correctly executed // the other one is through select (INT start, int length) method To implement richtextbox1.select (0, richtextbox1.rtf. length); // richtextbox1.rtf. length indicates the length of the text in RichTextBox // One is to directly select all using the selectall () method provided in the Net Framework // richtextbox1.selectall (); 

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.