Highlight the selected string or text in RichTextBox

Source: Internet
Author: User
Recently, the program needs to highlight a string in a piece of text and find the following information online. The example is as follows:
Private void highlighted (string to find the string) {// first find the start position of the string int start position = RichTextBox phrase display. find (to find the string); // determines whether it is found. If not, the start position is-1 If (start position> = 0) {RichTextBox phrase is displayed. selectionstart = start position; // obtain the length of the string. The RichTextBox phrase is displayed. selectionlength = string to be searched. length; // then you can change the color of this string to display the RichTextBox phrase. selectioncolor = color. red ;}}
Summary: RichTextBox is required to use a program to process the selected text or string in some formats. Normal textbox does not work.
The most common ones are:
RichTextBox. Find: Used to find a string and obtain its starting position.
RichTextBox. selectionstart: gets or sets the start position of the string to be selected.
RichTextBox. selectionlength: gets or sets the length of the string to be selected.
Finally, the format is set, and only one color is changed in the above instance,

You can change the size, Font, and so on as needed.

For example: RichTextBox phrase display. selectionfont = new font ("", 13 );

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.