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