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 );