Rich Text Box how to select a text block

I need a certain part of my text in RTB to be highlighted not in the sense of changing the font style / color, but in the sense of choosing a block with a certain color. This is similar to how Visual Studio selects a line during debug mode.

How can I perform this function using RTB, or rather, is it possible? If this is not possible, I would like to hear another way to accomplish the above task.

+5
source share
3 answers

I think you are looking for ScintillaNET .

On the other hand, if you want to do it yourself in RTB, you can do it by first finding lineNumberusing TextBoxBase.Lines . Then...

//Select the line from it number
startIndex = richTextBox.GetFirstCharIndexFromLine(lineNumber);
richTextBox.Select(startIndex, length);

//Set the selected text fore and background color
richTextBox.SelectionColor = System.Drawing.Color.White;
richTextBox.SelectionBackColor= System.Drawing.Color.Blue;
+7

, BackColor RichTextBox RichTextBox.SelectionBackColor.

int blockStart = 1; //arbitrary numbers to test
int blockLength = 15;
richTextBox1.SelectionStart = blockStart;
richTextBox1.SelectionLength = blockLength;
richTextBox1.SelectionBackColor = Color.Yellow;
+9

All Articles