asp.net RichTextBox highlight the selected string or text _ Practical tips

Source: Internet
Author: User
Example validation is as follows:
Copy Code code as follows:

private void Highlight (string to find string)
{
First find the starting position where you want to find the string
int start position =richtextbox phrase display. Find (to search for strings);
Judge if you find it, if you can't find it, then the start position is-1
If (start position >=0)
{
RichTextBox phrase display. SelectionStart = start position;
Get the length of the string
RichTextBox phrase display. SelectionLength = to find a string. Length;
And then you can change the color of the string.
RichTextBox phrase display. SelectionColor = color.red;
}
}

Summary: To use a program to do some formatting on the selected text or string requires the use of RichTextBox, the normal textbox is not.
One of the most common is:
Richtextbox.find: Used to find a string and get its starting position
Richtextbox.selectionstart: Gets or sets the starting position of the string to select
Richtextbox.selectionlength: Gets or sets the length of the string to be selected
Finally, the format is set up, the above example only changes a color,
Depending on your needs, you can also change the size, font, and so on.

For example: RichTextBox phrase display. SelectionFont = new Font ("bold", 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.