Richcollection colorcollect property and selectionbackcolor property

I want to select a specific line of text and highlight it with Blue Color, and I want the forecolor of this text to be white. I tried

 this.Select(start, length);
 this.SelectionBackColor = Color.Blue;
 this.SelectionColor = Color.White;

but that will not work. What's wrong? I want to simulate the effect that we get when we select any text through the mouse, where its back becomes light blue and the text inside becomes white. I can get it just by doing

 this.Select(start, length);

but then, as soon as he loses focus, the choice disappears, I want him to be permanent.

+3
source share
2 answers

Try to do something like this:

        this.richTextBox1.SelectionStart = start;
        this.richTextBox1.SelectionLength = length;
        this.richTextBox1.SelectionColor = Color.White;
        this.richTextBox1.SelectionBackColor = Color.Blue;
+2
source

richtextbox:

richtTextBox.SelectionColor = Color.Red;
richTextBox.SelectedText = "Red text";
richtTextBox.SelectionColor = Color.Green;
richTextBox.SelectedText = "Green text";

: enter image description here

+3

Source: https://habr.com/ru/post/1709110/


All Articles