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