The point is that the user selection works in the same way as the system selection, and the system selection itself is not shown.
int selectstart = RichTextBox.SelectionStart; int selectend = RichTextBox.SelectionLength; if (selectend >= 1) { RichTextBox.SelectionBackColor = Color.Gainsboro; RichTextBox.SelectionLength = 0; RichTextBox.SelectionStart = selectstart + selectend; } RichTextBox.SelectionBackColor = Color.White;
This code only works when I highlight further in the text, but does not work in the opposite direction. Those. I led the selection to the right in the text and without releasing the mouse button, I lead to the left and remove this selection. Already tried to add additional variables, subtract from the initial value, but failed. I know that my algorithm is more likely a crutch, but I just need to create my own selection, because the system for my program is not suitable. Can you advise how to improve this algorithm or how to create your custom selection?