Highlight the selected string or text in asp.net richTextBox

Source: Internet
Author: User

The instance verification is as follows:
Copy codeThe Code is as follows:
Private void highlighted (string to search for strings)
{
// First locate the start position of the string to be searched
Int start position = richTextBox phrase display. Find (to search for strings );
// Determine whether to find it. If not, the start position is-1.
If (start position> = 0)
{
RichTextBox phrase display. SelectionStart = start position;
// Obtain the string length
RichTextBox phrase display. SelectionLength = string to be searched. Length;
// Then the color of the string can be changed.
RichTextBox phrase display. 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 );

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.