I need a certain portion of my text in RTB to be highlighted not in the sense of changing the font style/color, but in the sense of making a block selection with a particular color. This is similar to how Visual Studio highlights a line during debug mode.
How can I accomplish this feature using RTB or rather, is it even possible? If it isn't possible, I'd like to hear another way of performing the above task.
How to highlight text using your keyboard. To highlight with the keyboard, move to the starting location using the arrow keys. Then, hold down the Shift key, and press the arrow key in the direction you want to highlight. Once everything you want is highlighted, let go of the Shift key.
Highlight selected text Select the text that you want to highlight. Go to Home and select the arrow next to Text Highlight Color. Select the color that you want.
Yes you can set the BackColor of a RichTextBox Selection using the RichTextBox.SelectionBackColor Property.
int blockStart = 1; //arbitrary numbers to test
int blockLength = 15;
richTextBox1.SelectionStart = blockStart;
richTextBox1.SelectionLength = blockLength;
richTextBox1.SelectionBackColor = Color.Yellow;
I think you are looking for ScintillaNET.
On the other hand if you want to do this by yourself in RTB then you can do it by first finding the lineNumber
using TextBoxBase.Lines property. Then ...
//Select the line from it's 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;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With